Post

Replies

Boosts

Views

Activity

Reply to Problems Updating a View
I tried that and it still does not seem to work. It is as if ContentView only takes a snapshot of the Data class when the app boots up and that's it. I there a function I could create to update the view once something is added to the array? ContentView just doesn't know when Data is updated.
Jan ’22
Reply to Problems Updating a View
Here is the Updated ContentView. I set the StateObject to be the reader and routed the data class instructions through the reader class by adding reader. in from of data. Am I interpreting what you said wrong? struct ContentView: View { //@StateObject var data = Data() @StateObject var reader : NFCReader = NFCReader()     var body: some View {         NavigationView {             List {                 Section(                     header: Text("\(reader.data.itemCount)" + " Items")                 ) { ForEach(reader.data.products, id: \.self) {                     product in Text(product)                 }                 .onDelete(perform: reader.data.deleteItem)                 .onMove(perform: reader.data.moveItem)             }             }             .navigationTitle("My Products")             .navigationBarItems(leading: EditButton(), trailing: AddButton)             .navigationViewStyle(.stack)         }         .environmentObject(reader.data) }     var AddButton: some View {         Button(action: {             reader.activate() //            data.addItem() // Next, once reader.activate() is done and sends data the tagUID, i need to open a new view with text imputs for name and description of product.         }, label: {             Image(systemName: "iphone.radiowaves.left.and.right")         })     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView() //        Do I need EnvironmentObject here???             .environmentObject(Data())     } }
Jan ’22