1

我在我的 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.

知道为什么会发生这种情况,或者我在排除故障时应该寻找什么?

4

1 回答 1

3

利用 :

NSString *propVal = [self.registrationRequest valueForKeyPath:propKey];
于 2013-04-12T17:52:08.203 回答