2013-08-16 6 views
17

私のcoredataのさまざまなバージョンを使用している移行を扱うiOSプロジェクトで作業しています。persistentstorecoordinator sqliteエラーコード:522 'エラーではありません'

は、私はまた、キャッチにif文を囲むしようと、それはSQLiteのエラーコード522

ここに何か問題があるのを返しますか?

私の次のコード:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator{ 
    if (__persistentStoreCoordinator != nil) { 
    return __persistentStoreCoordinator; 
    } 
    NSURL *storeURL = [[self applicationDocumentsDirectory]  
    URLByAppendingPathComponent:@"coredatadb.sqlite"]; 
    NSError *error = nil; 
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: 
    [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
    [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; 

    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]){ 

     [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]; 
     [__persistentStoreCoordinator release]; 
     __persistentStoreCoordinator = nil; 
     return [self persistentStoreCoordinator]; 
    } 

    return __persistentStoreCoordinator; 

答えて

3

一部の人々があなたのSQLiteデータベースにジャーナリングモードを変更することに対してアドバイスしますが、以下は、私の特定の問題を解決するようなので、それが見えます:

// Change journal mode from WAL to MEMORY 
NSDictionary *pragmaOptions = [NSDictionary dictionaryWithObject:@"MEMORY" forKey:@"journal_mode"]; 

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: 
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
pragmaOptions, NSSQLitePragmasOption, nil]; 
+0

あなたの入力のためのThnaks。 Kevinlのポイントに追加すると、 "MEMORY"の代わりに "DELETE"を使用できます。https://www.sqlite.org/pragma.html#pragma_journal_mode – Boobalan

38

を変更することによりジャーナルモードでは、問題を回避するだけですが、修正することはありません。新しいジャーナルモードでは、アプリにスピードのようなメリットがあります。

実際の問題は、そのモードで使用されている3つすべてではなく、1つのファイルだけを削除することです。 coredatadb.sqliteだけでなく、coredatadb.sqlite-shmおよびcoredatadb.sqlite-walファイルもあります。スキーマや先読みについて何か、詳細についてはコアデータのWWDC 2013ビデオをチェックしてください。

あなたの問題を解決するには、「coredatadb.sqlite」で始まるDocumentsディレクトリ内のすべてのファイルを削除する必要があり、すべてがiOSの9のための自由と;-)

を再度更新し簡単です:それは簡単で安全です今度はdestroyPersistentStoreAtURLまたはreplacePersistentStoreAtURLを使用します。 WWDC 2015セッション220_hd_whats_new_in_core_dataを参照してください。

+0

これは正解です。特定のパターンに一致するファイルを削除するには、この他のSO答えを使用してください:http://stackoverflow.com/questions/6179667/remove-files-matching-a-pattern-in-ios –

関連する問題