【发布时间】:2012-01-21 13:36:25
【问题描述】:
我正在尝试根据名为“名称”的属性从核心数据中获取实体。这是我的代码:
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *vegetable = [NSEntityDescription insertNewObjectForEntityForName:@"Vegetable" inManagedObjectContext:context];
// get the vegetable using name
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"name == %@", myGardenViewModel.vegetable.name];
[request setEntity:vegetable];
[request setPredicate:predicate];
NSError *error;
NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:request error:&error];
最后一行抛出如下异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Vegetable subentitiesByName]: unrecognized selector sent to instance 0x6bbcdd0'
有什么想法吗?
【问题讨论】: