0

两个实体:

  • 通知
  • 用户

Notificationrelationship与名为“”的用户一对一senderUser。在 NSManagedObject 文件中NotificationsenderUser看起来像这样

@property (nonatomic, retain) User *senderUser;

发件人用户有一个名为的 NSString 属性username

访问该属性的正确语法是什么?我尝试了以下方法,但出现错误:

Notification *managedObject = [array objectAtIndex:indexPath.row];
NSString *senderUN = [managedObject valueForKey:@"senderUser.username"];

错误:

 `*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Notification 0xbc4ad80> valueForUndefinedKey:]: the entity Notification is not key value coding-compliant for the key "senderUser.username"`.'
4

1 回答 1

2

你几乎是对的:

NSString *senderUN = [managedObject valueForKeyPath:@"senderUser.username"];

因为“senderUser.username”不是单个键,而是包含两个组件的键路径。

于 2013-09-09T20:59:10.847 回答