将xcdatamodel复制到现有项目时,应用程序会挂起错误:
Unresolved error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x1894f60 {URL=file://localhost/var/mobile/Applications/15214BCA-379F-4A2D-BE40-80F0CC25B50B/Documents/History.sqlite, metadata=<CFBasicHash 0x5b7880 [0x3f3c3630]>{type = immutable dict, count = 7,
entries =>
2 : <CFString 0x5b79a0 [0x3f3c3630]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x5b7a80 [0x3f3c3630]>{type = immutable, count = 0, values = ()}
4 : <CFString 0x5b79d0 [0x3f3c3630]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x5b7c00 [0x3f3c3630]>{value = +386, type = kCFNumberSInt64Type}
6 : <CFString 0x5b7a00 [0x3f3c3630]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x5b7aa0 [0x3f3c3630]>{type = immutable dict, count = 0,
entries =>
}
7 : <CFString 0x3eb4cf40 [0x3f3c3630]>{contents = "NSStoreUUID"} = <CFString 0x5b7d10 [0x3f3c3630]>{contents = "6FED3F04-493F-4A5B-9423-05475B6F3E0B"}
8 : <CFString 0x3eb4cde0 [0x3f3c3630]>{contents = "NSStoreType"} = <CFString 0x3eb4cdf0 [0x3f3c3630]>{contents = "SQLite"}
9 : <CFString 0x5b7a30 [0x3f3c3630]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x561a40 [0x3f3c3630]>{contents = "2"}
10 : <CFString 0x5b7a50 [0x3f3c3630]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x182b780 [0x3f3c3630]>{value = +3, type = kCFNumberSInt32Type}
}
, reason=Can't find model for source store}, {
URL = "file://localhost/var/mobile/Applications/15214BCA-379F-4A2D-BE40-80F0CC25B50B/Documents/History.sqlite";
metadata = {
NSPersistenceFrameworkVersion = 386;
NSStoreModelVersionHashes = {
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "6FED3F04-493F-4A5B-9423-05475B6F3E0B";
"_NSAutoVacuumLevel" = 2;
};
reason = "Can't find model for source store";
}
该模型取自具有相同类的另一个项目,并加载了选项:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
答案 0 :(得分:0)
我不知道你是否已经想到这一点,但你的问题可能在于你的程序AppDelagate.m中的这个方法:
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"DATABASENAME" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
其中'DATABASENAME'应该是.xcdatamodel文件的名称。