2016-10-18 1 views
0

私が正しく使用しているCoreDataのUIManagedDocumentがあります。 。 。addPersistentStoreWithTypeがnullを返します(iOS、CoreData、iCloud)

NSURL *localUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 
localUrl = [localUrl URLByAppendingPathComponent:@"Default Notes Database"]; 
//self.noteDatabase = [[UIManagedDocument alloc] initWithFileURL:localUrl] 

ここで、iCloudでコアデータを保存しようとする過程でNSPersistentStoreインスタンスを作成しようとしています。しかし、私のデータモデルとURLを使ってNSPersistentStoreを作成しようとすると、NSPersistentStoreは常にnilになります。

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Notes" withExtension:@"momd"]; 
NSPersistentStoreCoordinator *migrationPSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]]; 

// Open the store 
id sourceStore = [migrationPSC addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:iCloudUrl options:@{ NSPersistentStoreUbiquitousContentNameKey: @"InhoNotesiCloudStore",NSSQLitePragmasOption: @{@"journal_mode":@"DELETE"},NSMigratePersistentStoresAutomaticallyOption:@YES,NSInferMappingModelAutomaticallyOption:@YES } error:nil]; 

ソースストアはありません。なぜこれは無償ですか?私は答えを探したが、オンラインで何も見つけられなかった。

答えて

0

問題は、ストアファイルへのパスが間違っていた - 私は、シミュレータのアプリケーションファイルを使用してデバッグを見つけました。 .sqlite拡張子を使用するかどうかにかかわらずCoreDataを作成すると、ストアファイルはアプリケーションのドキュメントフォルダ内の別の場所に置かれます。私の場合は.sqlite拡張子がありませんでした。これは、私のストアファイルがDocuments/Default Notesデータベース/ storeContents/persistentStoreの代わりにDocuments/Default Notes Database.sqliteに配置されていることを意味します。

関連する問題