0

I am try to automatically assign the attribute value. I need to assign value for class attribute like bellow,

@property (nonatomic,retain)NSString *nid;
....
[self setValue:value forKey:@"nid"];

instead of,

[self setNid:value];

Problem i can't find method for handle the undefined key in my class. In NSDictionary have method for this,

[[dictionry allKeys]containsObject:@"nid"];

Is there any method similar to this handle my problem.

4

2 回答 2

1

我不确定你的意思,但是 NSKeyValueCoding 协议参考知道这个功能

- (id)valueForUndefinedKey:(NSString *)key

在 KVC 中存在未知密钥的情况下调用它。

于 2012-08-27T07:31:48.150 回答
0

如果找不到键,则被查询的对象会收到valueForUndefinedKey:消息。您可以覆盖其实现以找出未定义的键是什么。

于 2012-08-27T07:36:57.993 回答