Post

Replies

Boosts

Views

Activity

Reply to SwiftData: "Illegal attempt to establish a relationship 'item' between objects in different contexts
Still no solution that I’ve found. I posted on the Twitter dev community as well, and no one can find a solution. With further testing, I have found that sometimes it’s the type that you’re trying to use with the @Model macro. For example, it will throw a similar thread error if you attempt to use an enum type in a model as well.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to SwiftData: "Illegal attempt to establish a relationship 'item' between objects in different contexts
Forgot to mention, I made sure to add the new MyItem type to the schema as well: struct SwiftDataBugTestApp: App { var sharedModelContainer: ModelContainer = { let schema = Schema([ Item.self, MyItem.self ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) do { return try ModelContainer(for: schema, configurations: [modelConfiguration]) } catch { fatalError("Could not create ModelContainer: \(error)") } }() var body: some Scene { WindowGroup { ContentView() } .modelContainer(sharedModelContainer) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23