I am trying to add into @Model this class:
@Model
class Test: Identifiable {
var id: Int
var tasks: [Task] = []
init(id: Int, tasks: [Task]) {
self.id = id
self.tasks = tasks
}
}
while Task is a simple struct
struct Task: Identifiable {
var id: String
var name: String
init(name: String) {
self.id = UUID().uuidString
self.name = name
}
}
And I am getting this 3 errors: Referencing instance method 'setValue(for:to:)' on 'Array' requires that 'Task' conform to 'PersistentModel' and Referencing instance method 'getValue(for:)' on 'Array' requires that 'Task' conform to 'PersistentModel' and Referencing instance method 'setValue(for:to:)' on 'Array' requires that 'Task' conform to 'PersistentModel' exactly for the line in the Test class:
var tasks: [Task] = []
which opens hidden code as following:
{
init(newValue) accesses (_$backingData) {
_$backingData.setValue(for: \.tasks, to: newValue)
}
get {
_$observationRegistrar.access(self, keyPath: \.tasks)
return self.getValue(for: \.tasks)
}
set {
_$observationRegistrar.withMutation(of: self, keyPath: \.tasks) {
self.setValue(for: \.tasks, to: newValue)
}
}
}
Is it not possible to have an array as part of the new @Model SwiftData approach? Is there a simple fix for it that I cannot find out?