我正在開發iOS應用程序和CoreData。實體Shop不是密鑰值編碼兼容密鑰「category.name」
我有這兩個實體:
店
類別
我試圖從訪問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".'
我怎樣才能解決這個問題錯誤?
剛剛添加 - 這來自[Key-Value Coding](https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html) – Abizern
@Abizern謝謝!我已經通過添加的鏈接更新了我的答案。 – Gudiya