【发布时间】:2011-04-12 15:24:28
【问题描述】:
这条消息让我崩溃了:
'NSInvalidArgumentException',原因:'keypath name not found in entity
显然我没有正确查询我的实体。
//fetching Data
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Viewer" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSString *attributeName = @"dF";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",attributeName];
[fetchRequest setPredicate:predicate];
NSLog(@"predicate : %@",predicate);
NSError *error;
NSArray *items = [context executeFetchRequest:fetchRequest error:&error];
NSLog(@"items : %@",items);
[fetchRequest release];
//end of fetch
这是我的数据模型:
我想返回“dF”的值,不应该这样称呼它吗? :
NSString *attributeName = @"dF";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",attributeName];
【问题讨论】:
-
您的谓词中的
name是什么?您的实体上没有属性name! -
啊,这就是我感到困惑的地方。我想返回名称为 "dF" 的属性的值。
标签: objective-c swift core-data nsfetchrequest