|
Can someone explain my mistake here, I have really having difficulty with propertywrappers.
import Foundation import SwiftUI class arrayOfItems: ObservableObject, Identifiable { @Published var listOfItems = [Item]()
} class Item: ObservableObject, Identifiable { @Published var itemName: String = "" @Published var itemCount: UInt = 0 @Published var id = UUID() @Published var group: String
}
|
|
What exactly are the problems you are having with the code? I see one problem with your code. Your list view has only one item.
You need an array of items to show in the list. Another possible problem is using By the way the formatting is messed up for the code blocks that show the |
|
Where to start!! Other then what Tend to use
So the Data (
Changed
PS Added another button to add item to array to show list working |
|
thank you very mcuh for your help. I still have problem with appending array. my sheet view
My list view
|
|
Both the list view and the sheet view have the following property in your code:
Both views have their own To fix the problem you must do two things. First, use the
Second, pass the
You might have to change the order of the arguments. Read the following Hacking with Swift article for more details on working with How to use @ObservedObject to manage state from external objects |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.