Xcode 12. code and lifecycle are Swiftui.
I've looked at other peoples related questions and it seems like they just dump their entire projects code on here; it's a bit overwhelming to pick what I need from it. So, I've broken the issue down into the simplest example I can.
The goal is to have numberX iterate when I press the + button.
Thanks in advance!
struct InfoData: Identifiable {
var id = UUID()
var nameX: String
var numberX: Int
}
class ContentX: ObservableObject {
@Published var infoX = [
InfoData(nameX: "Example", numberX: 1)
]
}
struct ContentView: View {
@StateObject var contentX = ContentX()
var body: some View {
List(contentX.infoX) { item in
HStack {
Text("\(item.nameX)")
Spacer()
Button("+") {
item.numberX += 1 //Eror shows up here <<
}
Text("\(item.numberX)")
}
}
}
}