use*_*663 5 iphone core-data objective-c ios
我目前在Core-Data轻量级迁移方面遇到问题。深入研究之后,我发现模型中的一个实体上的NSStoreModelVersionHashes存在问题。实际上,甚至在我将模型版本添加到我的Core-Data模型之前,都发生了这种情况,并通过重新创建模型进行了验证。
我使用以下两种方法以编程方式获取了模型的版本哈希值:
NSDictionary * sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:[NSURL fileURLWithPath:storePath] error:&error];
NSDictionary * hashesFromMetadata = [sourceMetadata objectForKey:@“ NSStoreModelVersionHashes”];
和
NSMutableArray * filePaths = [[[NSMutableArray alloc] init];
NSString * directoryPath = [bundle pathForResource:modelName ofType:@“ momd”];
NSDirectoryEnumerator * enumerator = [[NSFileManager defaultManager] enumeratorAtPath:directoryPath];
NSString * filePath;
while(((filePath = [enumerator nextObject])!= nil){
if([[[filePath pathExtension] isEqualToString:@“ mom”]){
[filePaths addObject:[directoryPath stringByAppendingPathComponent:filePath]];
}
}
/ * Model.momd目录仅包含一个“ mom”文件:Model.mom” * /
NSURL * momURL = [NSURL fileURLWithPath:[filePaths objectAtIndex:0]];
NSManagedObjectModel *模型= [[NSManagedObjectModel分配] initWithContentsOfURL:momURL];
NSDictionary * hashesFromModel = [模型EntityVersionHashesByName];
令我惊讶的是,我发现我有两个不同的哈希值。请注意,我还没有添加任何模型版本,也完全没有修改模型。请参阅下面的EntityB的哈希值。
hashesFromMetadata:{
EntityA =“ 8fc59055 bd81d862 198a4cf8 160ab711 84191bd4 2340eb4b 1ceeb19b 4643f7d6”;
EntityB =“ bf73667d 19a25289 cd013e23 fc4524ce fb1095f9 6ad13aec f978ae1a 321388ed”;
EntityC =“ 4a55d875 fdb54969 c56d7add 201cb2c3 e244a5f1 b4950a74 55af1372 fa4f79b8”;
EntityD =“ 60fe2d8c e0061e78 c43f10aa 58cf1b5e 4cbb52a3 351ac83f 144ade9d 8687b22b”;
EntityE =“ 75c68768 31ef472b 567df030 36f99100 f52aa84e 7c8e2e81 1d070f07 cfd922be”
EntityF =“ 53823f0a 94745434 d9076b5c c8f8b153 b74a2f9c 06f15576 e5878527 d1309d4f”;
}
hashesFromModel:{
EntityA =“ 8fc59055 bd81d862 198a4cf8 160ab711 84191bd4 2340eb4b 1ceeb19b 4643f7d6”;
EntityB =“ c671f2ef 52eb91b1 73e4e9f2 92b70eed 9b09da23 ef66c016 4d684047 9d7b1efe”;
EntityC =“ 4a55d875 fdb54969 c56d7add 201cb2c3 e244a5f1 b4950a74 55af1372 fa4f79b8”;
EntityD =“ 60fe2d8c e0061e78 c43f10aa 58cf1b5e 4cbb52a3 351ac83f 144ade9d 8687b22b”;
EntityE =“ 75c68768 31ef472b 567df030 36f99100 f52aa84e 7c8e2e81 1d070f07 cfd922be”
EntityF =“ 53823f0a 94745434 d9076b5c c8f8b153 b74a2f9c 06f15576 e5878527 d1309d4f”;
}
我还检查了VersionInfo.plist文件的内容,发现哈希值与hashesFromModel中的哈希值相同。
显然,这种差异将始终导致Core-Data迁移失败并显示以下错误:“找不到源存储的模型”。
有人遇到过这个问题吗?知道如何在这种情况下执行轻量级迁移吗?非常感谢您的输入/反馈。
非常感谢。
| 归档时间: |
|
| 查看次数: |
422 次 |
| 最近记录: |