I have a struct that outlines the data, and then a class that has an array of the structs.
struct Example: Codable, Identifiable {
var id: UUID
var title: String
var description: String?
var tags: [String]
}
class Examples: ObservableObject {
@Published var examples = [Example]()
}
Then, I have a ForEach that displays the data with a button:
ForEach(examples.examples) { example in
VStack {
Button("Complete") {
example.completed = true
}
Text(example.title)
}
}
When I try to run, it gives me the error "Cannot assign to property: 'example' is a 'let' constant." I've tried passing the example into a separate view with an @Binding var (from this post ) and also modifying the data with an index (from this post), but both give me an error saying that Xcode was unable to produce a diagnostic report and to file feedback. How can I modify the data?
Sorry if this is a bad question, I'm pretty new to SwiftUI