Post

Replies

Boosts

Views

Activity

Reply to SwiftData - Context missing for optional
Thank you so much for your suggested solutions @Nevs! The third option that check modelContext == nil seems to work for me on iOS 18. For example this works for me var body: some View { Text("The school has \(school.students.count) students") Button("Delete school", action: { context.delete(school) try! context.save() }) } @Model SchoolModel { @Relationship(deleteRule: .cascade, inverse: \StudentModel.school) var swiftDataStudents: [StudentModel]? = [] } var students: [StudentModel] { set { swiftDataStudents = newValue } get { if self.modelContext == nil { return [] } return swiftDataStudents ?? [] } }
Nov ’24
Reply to SwiftData relationshipKeyPathsForPrefetching not working
FB16366153 (SwiftData relationshipKeyPathsForPrefetching not working)
Replies
Boosts
Views
Activity
Jan ’25
Reply to How to completely reset SwiftData?
How do I delete my own reply lol?
Replies
Boosts
Views
Activity
Nov ’24
Reply to SwiftData - Context missing for optional
Thank you so much for your suggested solutions @Nevs! The third option that check modelContext == nil seems to work for me on iOS 18. For example this works for me var body: some View { Text("The school has \(school.students.count) students") Button("Delete school", action: { context.delete(school) try! context.save() }) } @Model SchoolModel { @Relationship(deleteRule: .cascade, inverse: \StudentModel.school) var swiftDataStudents: [StudentModel]? = [] } var students: [StudentModel] { set { swiftDataStudents = newValue } get { if self.modelContext == nil { return [] } return swiftDataStudents ?? [] } }
Replies
Boosts
Views
Activity
Nov ’24