Model001.xcdatamodelモデルとの 2 つのバージョンがありModel002.xcdatamodelます。この2つがModel.xcdatamodeldバンドルされています。Model001to002.xcmappingmodelの一部ではないもありModel.xcdatamodeldます。私はチェックしました: xcmappingmodel と xcdatamodeld の両方が .app バンドルにコピーされます。
管理対象オブジェクトのコンテキストは次のように初期化されます。
NSURL *documentModel = [bundle URLForResource:@"Model" withExtension:@"momd"]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:documentModel]; return managedObjectModel;
initWithFileURL: また、UIManagedObjectサブクラスのオーバーライドでこれらのプロパティを設定します。
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:self.persistentStoreOptions]; [options setObject:@YES forKey:NSMigratePersistentStoresAutomaticallyOption]; [options setObject:@YES forKey:NSInferMappingModelAutomaticallyOption]; self.persistentStoreOptions = [options copy];
しかし、ドキュメントを開こうとすると、次のエラーが表示されます。
Can't find mapping model for migration
- アップデート -
手動で移行しても
[NSMappingModel mappingModelFromBundles:@[[NSBundle mainBundle]] forSourceModel:sourceObjectModel destinationModel:self.managedObjectModel];
これは nil を返します。Model001to002.cdm がアプリバンドルに含まれていることを再確認しましたが。アプリバンドルに含まれている必要がありますよね?