我在我的 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.
知道为什么会发生这种情况,或者我在排除故障时应该寻找什么?