I'm using the Xcode 6 document based application with core data template for OS X, which sets up the core data stack behind the scenes (no visible init code). Now I need to perform a simple core data lightweight migration and I have created the new versioned model and activated it. Do I really have to implement the core data stack initialisation by hand just to be able to pass migration permissions? If yes, where should the core data stack be initialised so that it will override the default?
Asked
Active
Viewed 453 times
0
-
nearly duplicate - check out this and it should work with swift and on OS X accordingly: http://stackoverflow.com/questions/2310216/implementation-of-automatic-lightweight-migration-for-core-data-iphone – Volker Apr 21 '15 at 11:50
1 Answers
2
You mentioned in a comment that you're using the document-based app template-- which is a crucial detail left out of the original question.
With this template you're using a subclass of NSPersistentDocument
. If you want to configure migration with NSPersistentDocument
, you need to override configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:
. Your implementation would call super
's implementation with a different set of options. Something like this:
override func configurePersistentStoreCoordinatorForURL(url: NSURL!, ofType fileType: String!, modelConfiguration configuration: String?, storeOptions: [NSObject : AnyObject]!, error: NSErrorPointer) -> Bool {
let options = [ NSMigratePersistentStoresAutomaticallyOption : true,
NSInferMappingModelAutomaticallyOption: true ]
return super.configurePersistentStoreCoordinatorForURL(url, ofType: fileType, modelConfiguration: configuration, storeOptions: options, error: error)
}

Tom Harrington
- 69,312
- 10
- 146
- 170
-
-
No, just copying and pasting from same the Xcode project template that the question mentioned. – Tom Harrington Apr 22 '15 at 01:13
-
I just created a CoreDataTest document based core data project and there is absolutely no core data stack code in AppDelegate. This is everything there is: `import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application } func applicationWillTerminate(aNotification: NSNotification) { // Insert code here to tear down your application } }` – Melodius Apr 22 '15 at 05:07
-
The Document.swift file does not have any core data stack setup code either. – Melodius Apr 22 '15 at 05:16
-
-
Should have mentioned you were using the document project template. That's completely different and requires a completely different answer. Edited.... – Tom Harrington Apr 22 '15 at 16:15
-