I am trying to use a SwiftData model but I keep getting the error for the code below.
'Element' is not a member type of class MyModel
Is this a bug or am I missing something?
@Model
final class MyModel {
var timestamp: Date
var favorites: [String]
init(timestamp: Date, favorites: [String]) {
self.timestamp = timestamp
self.favorites = favorites
}
public func remove(at index: Int) {
favorites.remove(at: index)
}
public func add(symbol: String) {
favorites.append(symbol)
}
}
public struct DetailView: View {
@Environment(\.modelContext) private var modelContext
@Query var model: MyModel
public var body: some View {
VStack { ... }
}
}