Xcode – SwiftUI ForEach index jump by 2
I am working on SwiftUI ForEach. Below image shows what I want to achieve. For this purpose I need next two elements of array in single iteration, so that I can show two card in single go. I search on…
I am working on SwiftUI ForEach. Below image shows what I want to achieve. For this purpose I need next two elements of array in single iteration, so that I can show two card in single go. I search on…
So I have this String "green" inside a constant (lernset.color). I would like to set a .foregroundColor() to a symbol (systemName: "folder") inside of a list, so that it has the same color as written inside the constant (lernset.color). The…
I have a navigation link and I need a different behavior when its label (MyView) is tapped depending on the edit mode (or any other condition): If we are not in edit mode, I want to trigger the navigation link…
I have a picker that will change an attribute of an object that is bound to the view. When the picker is changed I want to update the bound object so the change is apparent in the previous view. The…
I've got a simple HStack with subviews inside. How can I tell the first subview to be 60% the size of the HStack without using a GeometryReader? struct ContentView: View { var body: some View { HStack { Color.red.opacity(0.3) Color.brown.opacity(0.4)…
Can i not use switch to check for a variable and implement a view based on the variable's value. I tried using if else as well but still getting the same error. Do I have to create a method and…
I have the following code: struct ContentView: View { @Environment(.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Item.timestamp, ascending: true)], animation: .default) private var items: FetchedResults<Item> var body: some View { NavigationView { List { ForEach(items) { item in NavigationLink {…
I'm trying to create a gradient using the same color with a brightness modifier at one end. I tried this: let gradient = LinearGradient( colors: [Color.blue, Color.blue.brightness(0.1)], startPoint: .top, endPoint: .bottom) Unfortunately this does not compile with the following error:…
I'm trying to implement this solution: Combine, Publishers, and Core Data but I'm getting the following error: Here is my implantation: class DataModel: ObservableObject { @Published var customers: [Task] = [] private var cancellables = Set<AnyCancellable>() init(viewContext: NSManagedObjectContext) { CDPublisher(request:…
I am trying to use @AppStorage to read/save a value and calculate something with it, but I am failing to call a function within my ContentView. Example: Helper.swift func powerized(x: Decimal) -> Decimal { let powerized: Decimal = pow(x, 3)…