根据苹果的文档键值编码编程指南 http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/KeyValueCoding/Articles/DataTypes.html你可以在结构体属性上调用 valueForKey: 和 setValue:forKey: ,它们应该自动包装在 NSValue 对象中。我发现当我对 NSDecimal 进行此调用时,出现以下错误:
-[NSInvocation getArgument:atIndex:]: struct with unknown contents found while getting argument at index -1
谁能阐明这应该如何完成?或者在这种情况下 KVO 是否被破坏了......
看来键值编码不适用于包含以下内容的结构位字段。
所以对于这个测试类
typedef struct { int a; int b; } mystruct1;
typedef struct { int a:4; int b:4; } mystruct2;
@interface MyClass : NSObject
@property (nonatomic) mystruct1 s1;
@property (nonatomic) mystruct2 s2; // struct with bit fields
@end
以下工作,并返回NSValue
object:
MyClass *o = [[MyClass alloc] init];
mystruct1 s1 = { 4, 5 };
o.s1 = s1;
NSValue *v1 = [o valueForKey:@"s1"];
但是包含位字段的结构的相同代码会崩溃,并且完全相同
如您问题中的消息:
mystruct2 s2 = { 4, 5 };
o.s2 = s2;
NSValue *v2 = [o valueForKey:@"s2"]; // --> NSInvalidArgumentException
Since NSDecimal
包含位字段,这解释了问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)