UIManagedDocument創建包(文件夾)而不是原子存儲。該商店仍然在那裏,但它被埋在包裏。如果右鍵單擊在模擬器的「文檔」文件夾中創建的文件,您將能夠看到結構。默認值是
mydocument.foo
-> StoreContent
-> persistentStore
你需要做的是爲您的應用程序文件類型的一個新的擴展因此,例如,如果你的數據庫擴展爲.myappdb
,你需要創建項目中設置一個新的文檔類型,這可能是.myappdbw
什麼。您可以從入口在您把手在mydocumenturl
打開舊版文檔而不是傳遞,爲您的持久性存儲統籌創建上面的目錄結構點複製所有設置.myappdb
下一步。
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"];
然後將原有數據庫爲您創建
[[NSFileManager defaultManager] moveItemAtURL:mydocumenturl toURL:finalurl error:NULL];
的文件夾系統,然後你可以通過捆綁網址UIManagedDocument
UIManagedDocument *doc = [[UIManagedDocument alloc] initWithFileURL:newurl];
,這將是非常有用的鏈接對於iCloud整合是
http://developer.apple.com/library/ios/#releasenotes/DataManagement/RN-iCloudCoreData/_index.html
它的全部有點神祕,因爲迄今爲止承諾的示例代碼中的大部分都未能出現,但另一方面它的推導起來相當簡單。查看WWDC2011會議107,116和315獲取更多提示。
但要注意的是,如果你要使用此方法遷移舊版文檔DONT設置NSPersistentStoreUbiquitousContentNameKey
你遷移,因爲包當你改變點。上面的文檔很好地描述了它。
更好地使用'[文件管理replaceItemAtURL:storeURL withItemAtURL:legacyPersistentStoreURL backupItemName:無選項:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:零誤差:thisError ];'而不是複製和刪除,因爲複製不會覆蓋現有的文件 – Shmidt