开发者社区 问答 正文

IOS- “This class is not key value coding-compliant”

在ios应用中声明:

@interface UserRegistrationRequest : BaseServiceRequest
@property (nonatomic, retain) NSString *username;
@property (nonatomic, retain) NSString *password;
@property (nonatomic, retain) NSString *secretQuestionID;
@property (nonatomic, retain) NSString *secretQuestionAnswer;
@property (nonatomic, retain) UserProfile *profile;

@end

@interface UserProfile : NSObject
@property (nonatomic, retain) NSString *emailAddress;
@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *lastName;
@property (nonatomic, retain) NSData *profileImage;
@property (nonatomic, retain) NSNumber *dateOfBirth;
@end

我认为这些类应该是键值编码兼容
运行下面的代码:

NSString *propKey = @"profile.firstName";
NSString *propVal = [self.registrationRequest valueForKey:propKey];

报出异常:

[<UserRegistrationRequest 0xb6187f0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key profile.firstName.

不知道应该怎么解决?

展开
收起
爵霸 2016-03-24 08:44:50 2798 分享 版权
1 条回答
写回答
取消 提交回答
  • 使用这个:
    NSString *propVal = [self.registrationRequest valueForKeyPath:propKey];

    2019-07-17 19:11:49
    赞同 展开评论
问答分类:
问答标签:
问答地址: