2013-04-12 37 views
1

我在我的iOS應用程序中聲明以下類...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. 

任何想法,爲什麼這種情況正在發生或者我應該在解決此尋找?

回答

3

用途:

NSString *propVal = [self.registrationRequest valueForKeyPath:propKey]; 
+0

這就是它!不能相信我錯過了這一點。謝謝! – Shadowman

相關問題