Hello,
I have a iOS app I was looking at porting to Mac.
I'm having an issue with both the Mac (Designed for iPad) and Mac Catalyst Destinations. I can't test Mac due to too many build issues.
I'm trying to assign a new NSManagedObject into a NSPersistentStore.
let object = MyObject(context: context)
context.assign(object, to: nsPersistentStore)
This works fine for iOS/iOS Simulator/iPhone/iPad. But on the Mac it's crashing with
FAULT: NSInvalidArgumentException: Can't assign an object to a store that does not contain the object's entity.; {
Thread 1: "Can't assign an object to a store that does not contain the object's entity."
One of these two changes fixe my issue.
(1) My CoreDataStack was inside of a package, and the package didn't include .macCatalyst inside of the platforms.
Adding it fixed the issue.
platforms: [
.macCatalyst(.v26),
],
(2) Adding managedObjectContext to the view explicitly inside of a sheet
.sheet() {
View()
.environment(\.managedObjectContext, managedObjectContext)
}