Post

Replies

Boosts

Views

Activity

"'Element' is not a member type of class" error in SwiftData: What am I doing wrong?
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 { ... } } }
4
1
1.6k
Jan ’24