我有一个像这样的对象 MyObject 设置
@interface MyObject : NSObject {
int time;
}
@property (nonatomic, assign) int time;
@end
我正在尝试使用 KVC 设置值,我的代码如下所示:
MyObject* obj = [MyObject alloc] init];
int val = 2;
NSValue* nsvalue = [NSValue valueWithBytes:&val objCType:@encode(int)];
[obj setValue:nsvalue forKey:@"time"]; // here I get the exception
当我运行这段代码时,我得到一个这样的异常:
-[NSConcreteValue intValue]: unrecognized selector sent to instance 0x6e0f670
我尝试过使用其他数据类型(浮点数)并得到相同的异常。我也尝试过使用它来获得价值valueForKey
,并且效果很好。
有任何想法吗?