我尝试在iOS 7设备上运行此代码(实际上它在模拟器上运行良好) 我使用了MR 2.2并使用mogenerator生成了Core Data类
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext){
NewsEntity *newsEntity = [NewsEntity MR_createInContext:localContext];
newsEntity.newsId = jsonObject[@"News_Id"];
}
completion:^(BOOL success, NSError *error){
if (!success || nil != error)
{
NSLog(@"MagicalRecord saveWithBlock error: %@", error.description);
}
else
{
[self updateUI];
}
}];
我对这行代码有例外
NewsEntity *newsEntity = [NewsEntity MR_createInContext:localContext];
bt看起来像那样
* thread #5: tid = 0x31b342, 0x3aaafcc0 libobjc.A.dylib`objc_exception_throw, queue = 'NSManagedObjectContext Queue', stop reason = breakpoint 3.3
* frame #0: 0x3aaafcc0 libobjc.A.dylib`objc_exception_throw
frame #1: 0x2fd50030 CoreData`+[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:] + 204
frame #2: 0x00053f02 TestApp`+[_NewsEntity insertInManagedObjectContext:](self=0x00be4480, _cmd=0x369db6dc, moc_=0x16789640) + 322 at _NewsEntity.m:28
frame #3: 0x0014de3e TestApp`+[NSManagedObject(self=0x00be4480, _cmd=0x00975bb0, context=0x16789640) MR_createInContext:] + 138 at NSManagedObject+MagicalRecord.m:157
frame #4: 0x00057df4 TestApp`__52-[NewsViewController saveDataToPersistentStorage:]_block_invoke(.block_descriptor=<unavailable>, localContext=0x16789640) + 472 at NewsViewController.m:115
frame #5: 0x00144282 TestApp`__51+[MagicalRecord(.block_descriptor=<unavailable>) saveWithBlock:completion:]_block_invoke + 46 at MagicalRecord+Actions.m:28
frame #6: 0x2fdaca70
我也有像这样的终止例外
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an entity named 'NewsEntity' in this model.'
我只添加了[MagicalRecord setupAutoMigratingCoreDataStack];到AppDelegate
你能解决这个问题吗?
答案 0 :(得分:0)
抱歉,我忘了将核心数据模型添加到目标会员