0
我新的实体部分attribures,然后得到这样的错误:coredata .xcdatamodel创建错误.mom,导致无法为新属性设置值,有没有解决方法?今天
LOLHelper[3393:101073] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MatchList_EN setSummonerName:]: unrecognized selector sent to instance 0x60800048f370'
后来我发现我无法找到.sqlist/.mom文件新列/项目,我不知道。我试着重新创建NSManagedObject的子类,卸载并安装应用程序,创建新版本.xcdatamodel,但都不工作。
帕蒂的代码是在这里:
NSManagedObjectContext * contextMatchList_EN = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
NSPersistentContainer * psc =[[NSPersistentContainer alloc] initWithName:@"LOLHelper"];
[psc loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription * storeDescription, NSError * error) {
if (error != nil) {
NSLog(@"Unresolved error %@, %@", error, error.userInfo);
abort();
}
}];
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"LOLHelper" withExtension:@"momd"];
NSLog(@"%@", modelURL);
[contextMatchList_EN setPersistentStoreCoordinator:psc.persistentStoreCoordinator];
parentContext = contextMatchList_EN;
[parentContext performBlockAndWait:^{
// MatchList_EN * MatchList_ENEntity = [NSEntityDescription insertNewObjectForEntityForName:@"MatchList_EN" inManagedObjectContext:parentContext];
MatchList_EN * MatchList_ENEntity = [[MatchList_EN alloc] initWithEntity:[NSEntityDescription entityForName:@"MatchList_EN" inManagedObjectContext:parentContext] insertIntoManagedObjectContext:parentContext];
///存储所有的属性名称
NSMutableArray *allNames = [[NSMutableArray alloc] init];
///存储属性的个数
unsigned int propertyCount = 0;
///通过运行时获取当前类的属性
objc_property_t *propertys = class_copyPropertyList([MatchList_ENEntity class], &propertyCount);
NSLog(@"class is %@", NSStringFromClass(MatchList_ENEntity.class));
//把属性放到数组中
for (int i = 0; i < propertyCount; i ++) {
///取出第一个属性
objc_property_t property = propertys[i];
const char * propertyName = property_getName(property);
[allNames addObject:[NSString stringWithUTF8String:propertyName]];
NSLog(@"propert is %@", [NSString stringWithUTF8String:propertyName]);
}
///释放
free(propertys);
if (matchListM != nil) {
[matchListM setValue:[[self getSummonerInfo_EN] objectForKey:@"accountId"] forKey:@"accountId"];
[matchListM setValue:[[self getSummonerInfo_EN] objectForKey:@"name"] forKey:@"summonerName"];
for (key in matchListM.allKeys) {
value = [NSString stringWithFormat:@"%@",[matchListM objectForKey:key]];
if ([key isEqualToString:@"summonerName"]) {
MatchList_ENEntity.summonerName = value;
}
[MatchList_ENEntity setValue:value forKey:key];
}
// [gameIdArr addObject:[matchList objectForKey:@"gameId"]];
}
我还检查类型ManagedObject和它的属性,但它是正确!!!!
2017-07-16 00:48:14.173901+0800 LOLHelper[3393:101073] class is MatchList_EN
2017-07-16 00:48:14.174073+0800 LOLHelper[3393:101073] propert is accountId
2017-07-16 00:48:14.174169+0800 LOLHelper[3393:101073] propert is assistMost
2017-07-16 00:48:14.174302+0800 LOLHelper[3393:101073] propert is assists
2017-07-16 00:48:14.174476+0800 LOLHelper[3393:101073] propert is champion
2017-07-16 00:48:14.174591+0800 LOLHelper[3393:101073] propert is damageMost
2017-07-16 00:48:14.174862+0800 LOLHelper[3393:101073] propert is deaths
2017-07-16 00:48:14.175039+0800 LOLHelper[3393:101073] propert is doubleKill
2017-07-16 00:48:14.175233+0800 LOLHelper[3393:101073] propert is endIndex
2017-07-16 00:48:14.175407+0800 LOLHelper[3393:101073] propert is gameCreation
2017-07-16 00:48:14.175514+0800 LOLHelper[3393:101073] propert is gameId
2017-07-16 00:48:14.175640+0800 LOLHelper[3393:101073] propert is gameMode
2017-07-16 00:48:14.175772+0800 LOLHelper[3393:101073] propert is gameType
2017-07-16 00:48:14.175931+0800 LOLHelper[3393:101073] propert is killMost
2017-07-16 00:48:14.176189+0800 LOLHelper[3393:101073] propert is kills
2017-07-16 00:48:14.176455+0800 LOLHelper[3393:101073] propert is lane
2017-07-16 00:48:14.176632+0800 LOLHelper[3393:101073] propert is minionMost
2017-07-16 00:48:14.176915+0800 LOLHelper[3393:101073] propert is moneyMost
2017-07-16 00:48:14.177136+0800 LOLHelper[3393:101073] propert is mvp
2017-07-16 00:48:14.177367+0800 LOLHelper[3393:101073] propert is pentaKill
2017-07-16 00:48:14.177613+0800 LOLHelper[3393:101073] propert is platformId
2017-07-16 00:48:14.177784+0800 LOLHelper[3393:101073] propert is quadraKill
2017-07-16 00:48:14.177975+0800 LOLHelper[3393:101073] propert is queue
2017-07-16 00:48:14.178073+0800 LOLHelper[3393:101073] propert is role
2017-07-16 00:48:14.178224+0800 LOLHelper[3393:101073] propert is season
2017-07-16 00:48:14.178418+0800 LOLHelper[3393:101073] propert is startIndex
2017-07-16 00:48:14.178576+0800 LOLHelper[3393:101073] propert is summonerName
2017-07-16 00:48:14.178746+0800 LOLHelper[3393:101073] propert is takenMost
2017-07-16 00:48:14.178865+0800 LOLHelper[3393:101073] propert is timestamp
2017-07-16 00:48:14.179049+0800 LOLHelper[3393:101073] propert is totalGames
2017-07-16 00:48:14.179188+0800 LOLHelper[3393:101073] propert is tripleKill
2017-07-16 00:48:14.179313+0800 LOLHelper[3393:101073] propert is turretMost
2017-07-16 00:48:14.179507+0800 LOLHelper[3393:101073] propert is win
2017-07-16 00:48:14.179663+0800 LOLHelper[3393:101073] propert is listToMatch