我正在使用 CoreData 开发一个 iOS 应用程序。
我有这两个实体:
店铺
类别
我正在尝试category.name
从Shop
实体访问,但出现错误:
- (void)updateDetails:(NSManagedObject *)shop
{
NSLog(@"updateDetails: %@", shop);
if (shop == nil)
return;
self.nameLabel.text = [[shop valueForKey:@"name"] description];
self.categoryLabel.text = [[shop valueForKey:@"category.name"] description];
self.addressLabel.text = [[shop valueForKey:@"address"] description];
self.telephoneLabel.text = [[shop valueForKey:@"telephone"] description];
NSNumberFormatter* f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber* acceptRate = [f numberFromString:[[shop valueForKey:@"acceptRate"] description]];
_ratingControl.rating = [acceptRate unsignedIntValue];
}
我以这种方式检索Shop
实体:
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Shop"
inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSArray *results = [context executeFetchRequest:fetchRequest error:nil];
但我得到这个错误:
'[<NSManagedObject 0x1cdb4890> valueForUndefinedKey:]: the entity Shop is not key value coding-compliant for the key "category.name".'
我该如何解决这个错误?