2011-07-24 7 views
0

問題が発生しました自動軽量移行私のApp Delegateのコード!コアデータの自動Lightwieight移行問題

アップルのすべてのドキュメントを"Automatic Lightweight Migration"について読んでいますが、結局のところ、Automatic Lightweight Migrationに用意されているコードを使用する方法が見つかりません。

最近、data modelEntityにいくつかの新しいAttributeを追加しました。古いデータを保存したいと思います。

私のアプリデリゲートのコードは次のようである:

- (NSPersistentStoreCoordinator *) persistentStoreCoordinator { 


    if (__persistentStoreCoordinator) { 
     return __persistentStoreCoordinator; 
    } 

    NSManagedObjectModel *mom = [self managedObjectModel]; 
    if (!mom) { 
     NSLog(@"%@:%@ No model to generate a store from", [self class], NSStringFromSelector(_cmd)); 
     return nil; 
    } 

    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSURL *applicationFilesDirectory = [self applicationFilesDirectory]; 
    NSError *error = nil; 

    NSDictionary *properties = [applicationFilesDirectory resourceValuesForKeys:[NSArray arrayWithObject:NSURLIsDirectoryKey] error:&error]; 

    if (!properties) { 
     BOOL ok = NO; 
     if ([error code] == NSFileReadNoSuchFileError) { 
      ok = [fileManager createDirectoryAtPath:[applicationFilesDirectory path] withIntermediateDirectories:YES attributes:nil error:&error]; 
     } 
     if (!ok) { 
      [[NSApplication sharedApplication] presentError:error]; 
      return nil; 
     } 
    } 
    else { 
     if ([[properties objectForKey:NSURLIsDirectoryKey] boolValue] != YES) { 
      // Customize and localize this error. 
      NSString *failureDescription = [NSString stringWithFormat:@"Expected a folder to store application data, found a file (%@).", [applicationFilesDirectory path]]; 

      NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 
      [dict setValue:failureDescription forKey:NSLocalizedDescriptionKey]; 
      error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:101 userInfo:dict]; 

      [[NSApplication sharedApplication] presentError:error]; 
      return nil; 
     } 
    } 

    NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"FinancingPro.storedata"]; 
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom]; 
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error]) { 
     [[NSApplication sharedApplication] presentError:error]; 
     [__persistentStoreCoordinator release], __persistentStoreCoordinator = nil; 
     return nil; 
    } 

    return __persistentStoreCoordinator; 

今、私は自動軽量移行を持っているために、このコードを変更する方法がわかりません!
私のdbはではありません。 SQLliteです。

答えて

2

あなたはここにNSInferMappingModelAutomaticallyOptionキーでオプション辞書を設定する必要があります:あなたは任意の移行を無視するストアを言っているoptionsにnil値を渡すことで

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

+0

+1オプションディクショナリをオプションに渡して質問をした直後に問題を解決しました。とにかくありがとうございました。 – Prooshani