程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-IOS- “This class is not key value coding-compliant”

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

編輯:編程綜合問答
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.

不知道應該怎麼解決?

最佳回答:


使用這個:

NSString *propVal = [self.registrationRequest valueForKeyPath:propKey];
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved