Also, why can't I just put objectWillChange.send() in the Data class? I tries adding it to the addItem, deleteItem and moveItem functions but it did not seem to do anything.
Post
Replies
Boosts
Views
Activity
That (kinda) Worked! The content view now updates whenever the reader tells it to, though I still have problems with deleting or moving items in the array from content view. Whenever I delete something from the array it just refuses to do it, and whenever I try to move something, the whole app crashes, giving me this error: (Fatal error: Array index is out of range). Any thoughts on what to do here?
Also in the reader class data was set to published.
import CoreNFC
struct ContentView: View {
@State var reader: NFCReader = NFCReader()
@State var tagCode = "UID"
var body: some View {
VStack{
Text(tagCode)
Button {
reader.activate()
tagCode = reader.tagUID
} label: {
Text("Scan")
.font(.title)
}.padding()
}
}
}
Got it. The problem I am running into now is that when I make a @State variable in the view, when I press a button it is supposed to run the NFC program with ()activate and then update the variable tagCode to be equal to reader.tagUID, but it assigns the value before the reader gives tagUID a new UID. is there a way to update the variable only after the NFC program is done running?