我正在使用 setValuesForKeysWithDictionary 来填充我的模型对象。模型对象定义为
@interface Media : NSObject
{
NSString *userId;
NSString *mediaType;
}
@property(nonatomic,copy) NSString *userId;
@property(nonatomic,copy) NSString *mediaType;
属性合成看起来像,
@implementation Media
@synthesize userId;
@synthesize mediaType;
我初始化类如下,
NSMutableDictionary *dic = [NSMutableDictionary new];
[dic setValue:@"aaa" forKey:@"userId"];
[dic setValue:@"bbb" forKey:@"mediaType"];
Media *obj = [[Media alloc] init];
[obj setValuesForKeysWithDictionary:dic];
这与消息一起崩溃
'[<Media 0x8a9f280> valueForUndefinedKey:]: this class is not key value coding-compliant for the key aaa.'
为什么 setValuesForKeysWithDictionary: 把我的价值当作关键?还是我误解了 setValuesForKeysWithDictionary: 函数的目的?