UIManagedDocument creates packages (folders), not atomic ones. The store is still there, but he was buried in a package. If you right-click the file created in the Documents folder in the simulator, you can see the structure. Defaults to
mydocument.foo -> StoreContent -> persistentStore
What you need to do is create a new extension for your application file type, for example, if the .myappdb
database .myappdb
you need to create a new document type in the project settings, which can be .myappdbw
. You can copy all the settings from the entry for .myappdb
Further, at the moment when you are processing the opening of an obsolete document in mydocumenturl
instead of passing it to the permanent repository coordinator, you create the directory structure above.
NSURL *newurl = [[mydocumenturl URLByDeletingPathExtension] URLByAppendingPathExtension:@"myappdbw"]; NSURL *desturl = [newurl URLByAppendingPathComponent:@"StoreContent"]; [[NSFileManager defaultManager] createDirectoryAtURL:desturl withIntermediateDirectories:YES attributes:nil error:NULL]; NSURL *finalurl = [desturl URLByAppendingPathComponent:@"persistentStore"];
and then move the obsolete database to the folder you created.
[[NSFileManager defaultManager] moveItemAtURL:mydocumenturl toURL:finalurl error:NULL];
and then you can pass the url of the UIManagedDocument package
UIManagedDocument *doc = [[UIManagedDocument alloc] initWithFileURL:newurl];
A link that will be useful for iCloud integration,
http://developer.apple.com/library/ios/#releasenotes/DataManagement/RN-iCloudCoreData/_index.html
This is all a bit mysterious, since most of the promised code sample has not yet appeared, but, on the other hand, it is basically quite simple to output. Take a look at WWDC2011 sessions 107,116 and 315 for more tips.
But note that if you intend to use this method to migrate legacy DONT documents, set NSPersistentStoreUbiquitousContentNameKey
to the point that you migrate because the package changes when you do. The dock above describes this pretty well.