I have added a Today Extension in my existing app and setup a separate core data stack(reusing the same code which is used to setup core data for the main app).
My app data gets deleted when I run the Today extension as if setting up of Today core data stack deletes the existing data. Refer below code for returning persistentCoordinator
:
let options = [NSMigratePersistentStoresAutomaticallyOption:true,
NSInferMappingModelAutomaticallyOption:true,
NSSQLitePragmasOption:["journal_mode":"MEMORY"]]
var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: options, error: &error) == nil {
NSLog("Unresolved error \(error)")
}
return coordinator