|
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 |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
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.