XCode 12 beta 5: Core data crash in multiplatform template

anoop m
2 min readAug 24, 2020

--

Recently I was playing with XCode 12 beta 5, I created a project in multiplatform template and turned on coredata support. When I ran the project as such, it straight away crashed giving the below error

2020-08-24 10:35:34.024610+0200 CrashTest[4429:64485] [error] error:  Failed to load model named CrashTest
CoreData: error: Failed to load model named CrashTest
2020-08-24 10:35:34.053096+0200 CrashTest[4429:66074] libMobileGestalt MobileGestaltCache.c:38: No persisted cache on this platform.
2020-08-24 10:35:34.068970+0200 CrashTest[4429:64485] [error] error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'Item' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
CoreData: error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'Item' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
2020-08-24 10:35:34.069071+0200 CrashTest[4429:64485] [error] error: +[Item entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
CoreData: error: +[Item entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
Fatal error: UnsafeRawBufferPointer with negative count: file Swift/UnsafeRawBufferPointer.swift, line 872
2020-08-24 10:35:34.168463+0200 CrashTest[4429:64485] Fatal error: UnsafeRawBufferPointer with negative count: file Swift/UnsafeRawBufferPointer.swift, line 872

Fix is simple and crazy

If you look into the project you can see the name of the model file as

Shared.xcdatamodeld

But in the code Persistence.swift it uses the project name for the file

init(inMemory: Bool = false) {
container = NSPersistentContainer(name: "CrashTest") <----
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}

Just change the name to Shared and it will build and run fine at least in iOS. I use Mac 10.15 hence couldnt test the macOS App. I ran it in simulator…dont know whether it makes a difference… raised a feedback also with Apple

init(inMemory: Bool = false) {
container = NSPersistentContainer(name: "Shared")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}

--

--

No responses yet