iOS Swift NSCoreDataCoreSpotlightDelegate crash: "Can't add store"

150 Views Asked by At

We are using Core Data with Core Spotlight integration. Very sporadic Crashlytics sends an error report about with the crash NSInvalidArgumentException reads as "Can't add store". We never had this problem in development nor during testing. We have configured Core Data and Spotlight like this:

let mom = NSManagedObjectModel(contentsOf: modelURL)

let container = NSPersistentContainer(name: "DataModel", managedObjectModel: mom!)
container.persistentStoreDescriptions = [NSPersistentStoreDescription(url: storeURL)]
if let persistentStoreDesc = container.persistentStoreDescriptions.first {
   persistentStoreDesc.shouldInferMappingModelAutomatically = false
   persistentStoreDesc.shouldMigrateStoreAutomatically = false
   persistentStoreDesc.type = NSSQLiteStoreType
   let spotlightDelegate = CoreDataCoreSpotlightDelegate(forStoreWith: persistentStoreDesc, model: container.managedObjectModel)
   persistentStoreDesc.setOption(spotlightDelegate, forKey: NSCoreDataCoreSpotlightExporter)
}  

I have searched the internet and cam up with one person who has the same problem https://forums.developer.apple.com/thread/115897

Did any of you had the same problem and knows a solution?

The last time it happened it was on: OS Version: 12.0.1 (16A404) Device: iPad Air 2

1

There are 1 best solutions below

0
cfihelp On

That's my post from a while back - sorry, I should have followed up on it! I talked to an engineer at WWDC who informed me that it was fixed in iOS 13. And indeed, we have not seen that crash on any 13 variant. As far as I know there is no workaround for prior versions of iOS. Sorry to be the bearer of bad news.