1

編集

私はこれをここに再投稿しました: Xcode 4.3 の Core Data & UIManagedDocument: Can't merge models

別のエラーを表示することができました。

編集の終わり

そのため、共有を使用した Core Data App を作成していUIManagedDocumentます。UIManagedDocumentヘルパー クラスを使用してこれにアクセスしますDocumentHandler。別のクラスで次のように使用できることを願っていますviewWillAppear

if (!self.document) {
        [[DocumentHandler sharedDocumentHandler] performWithDocument:^(UIManagedDocument *document) {
            self.document = document;            
            [self setupFetchedResultsController];
        }]; 
    }

`

- (id)init {
    self = [super init];
    if (self) {
        NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
        url = [url URLByAppendingPathComponent:@"MyJimDocument"];

        self.document = [[UIManagedDocument alloc] initWithFileURL:url];

        // Set our document up for automatic migrations
        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
        self.document.persistentStoreOptions = options;

        // Register for notifications
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(objectsDidChange:)
                                                     name:NSManagedObjectContextObjectsDidChangeNotification
                                                   object:self.document.managedObjectContext];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(contextDidSave:)
                                                     name:NSManagedObjectContextDidSaveNotification
                                                   object:self.document.managedObjectContext];
    }
    return self;
}


- (void)performWithDocument:(OnDocumentReady)onDocumentReady {    
    void (^OnDocumentDidLoad)(BOOL) = ^(BOOL success) {
        onDocumentReady(self.document);
    };

    if (![[NSFileManager defaultManager] fileExistsAtPath:[self.document.fileURL path]]) {
        [self.document saveToURL:self.document.fileURL
                forSaveOperation:UIDocumentSaveForCreating
               completionHandler:OnDocumentDidLoad];
    } else if (self.document.documentState == UIDocumentStateClosed) {
        [self.document openWithCompletionHandler:OnDocumentDidLoad];
    } else if (self.document.documentState == UIDocumentStateNormal) {
        OnDocumentDidLoad(YES);
    }
}

'

ドキュメントのコンテキストを使用して、NSManagedObjects を作成します (標準の Core Data のものですよね?)。問題は、アプリを実行すると次のエラーが発生することです。

「名前が異なる 2 つのエンティティを持つモデルをマージできません」

私はこの DocumentHandler で頭がいっぱいです。これが簡単な修正であることを願っています。

私はデータモデルなどの個別のバージョンを作成したことはなく、何も移行しようとはしていません。このアプリを初めて実行したいだけです。

読んでくれてありがとう。

4

0 に答える 0