我在这行代码中运行时抛出了一个错误:
[numberFormatter setCurrencySymbol:[theObject valueForKey:kFieldCurrency]];
kFieldCurrency是一个常量,定义如下:
#define kValueCurrency @"currency"
打印theObject的值提供此输出: 打印对象的描述:
<NSManagedObject: 0x7836bf0> (entity: CustomValue; id: 0x78373d0 <x-coredata://84240925-2D7D-485E-AD9D-8DD48F602C00/CustomValue/p5> ; data: {
contract = "0x78e4a20 <x-coredata://84240925-2D7D-485E-AD9D-8DD48F602C00/Contract/p3>";
currency = "0x7839810 <x-coredata://84240925-2D7D-485E-AD9D-8DD48F602C00/Currency/p5>";
dateTimeValue = nil;
isChangeableByUser = 1;
isListed = 1;
listName = GELDWERT;
numValue = 10;
numberOfDigits = 0;
stringValue = nil;
tagName = GELDWERT;
type = 5;
})
错误消息是:
-[NSManagedObject copyWithZone:]: unrecognized selector sent to instance 0x7c1c930
和:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject copyWithZone:]: unrecognized selector sent to instance 0x7c1c930'
*** First throw call stack:
(0x1959012 0x1690e7e 0x19e44bd 0x1948bbc 0x194894e 0xe77afd 0x28d4d 0x2922f 0x2c53a 0x2d14f 0x2d67a 0x27ecd 0x3a61c7 0x3a6232 0x3a64da 0x3bd8e5 0x3bd9cb 0x3bdc76 0x3bdd71 0x3be89b 0x3bee93 0xc8d83f7 0x3bea88 0x71ae63 0x70cb99 0x3a6dd2 0xc8d012c 0x10763 0x16a4705 0x2c82c0 0x504a64 0x16a4705 0x2c82c0 0x2c8258 0x389021 0x38957f 0x3886e8 0x2f7cef 0x2f7f02 0x2d5d4a 0x2c7698 0x23c5df9 0x23c5ad0 0x18cebf5 0x18ce962 0x18ffbb6 0x18fef44 0x18fee1b 0x23c47e3 0x23c4668 0x2c4ffc 0x289d 0x27c5)
libc++abi.dylib: terminate called throwing an exception
我注意到,NSObject
(NSManagedObject
继承)实现+copyWithZone:
但没有-copyWithZone:
。错误消息表明copyWithZone:已经发送了该类的实例,而不是类本身。
theObject
是本地方法的参数。
- (NSString *) outputValue: (NSManagedObject *) theObject {...}
你在调试器输出中看到它确实属于那种类型。并且它的属性currency
与nil
不同。
有什么想法吗? 我很乐意提供更多的代码,但我还不知道你可以引用哪些代码片段。
这是基于当前xcode和copiler版本的一般可用的SDK 6.1,不是当前环绕的beta版本。
答案 0 :(得分:3)
从您的NSLog输出
<NSManagedObject: 0x7836bf0> (entity: CustomValue; id: 0x78373d0 <x-coredata://84240925-2D7D-485E-AD9D-8DD48F602C00/CustomValue/p5> ; data: {
contract = "0x78e4a20 <x-coredata://84240925-2D7D-485E-AD9D-8DD48F602C00/Contract/p3>";
currency = "0x7839810 <x-coredata://84240925-2D7D-485E-AD9D-8DD48F602C00/Currency/p5>";
...
似乎“货币”是与另一个实体的关系,所以
[theObject valueForKey:kFieldCurrency]
将返回该实体的对象,而不是setCurrencySymbol:
方法所期望的字符串。
也许你想要类似于
的东西[numberFormatter setCurrencySymbol:[theObject valueForKeyPath:@"currency.symbol]];
假设“symbol”是“Currency”实体的字符串属性。