Post

Replies

Boosts

Views

Activity

Reply to How to subclass with SwiftData?
My workaround was to change the super class into a protocol. This doesn't help avoiding redundant code in the subclasses, but it will enable you to use the Protocol in a similar way you might use a Super class in your code while still being able to take advantage of SwiftData. This is not idea and hopefully will get fixed by Apple.
Topic: App & System Services SubTopic: iCloud Tags:
Oct ’23
Reply to SwiftData: "Illegal attempt to establish a relationship 'item' between objects in different contexts
What I find interesting is that the crash (for me) occurs not upon calling insert using the ModelContext, but in the constructor of the @Model (e.g. MyItem in your example). This is another surprise as I don't this the ModelContext is even used by the backingData.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to SwiftData: "Illegal attempt to establish a relationship 'item' between objects in different contexts
Any luck figuring this one out? I have two almost identical situations in my app ... one works, the other doesn't ... and I can't seem to figure out why. They both get the ModelContext from the same environment so the error message doesn't make much sense.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to How to subclass with SwiftData?
My workaround was to change the super class into a protocol. This doesn't help avoiding redundant code in the subclasses, but it will enable you to use the Protocol in a similar way you might use a Super class in your code while still being able to take advantage of SwiftData. This is not idea and hopefully will get fixed by Apple.
Topic: App & System Services SubTopic: iCloud Tags:
Replies
Boosts
Views
Activity
Oct ’23