Hermann Klecker
Hermann Klecker

Reputation: 14068

NSManagedobject copywithzone unrecognised selector

I have got an error thrown on runtime in this line of code:

[numberFormatter setCurrencySymbol:[theObject valueForKey:kFieldCurrency]];

kFieldCurrency is a constant defined as follows:

#define kValueCurrency          @"currency"

Printing the value of theObject provides this output: Printing description of 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;
})

The error message is:

-[NSManagedObject copyWithZone:]: unrecognized selector sent to instance 0x7c1c930

and:

*** 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

I have noticed, that NSObject (from which NSManagedObject inherits) implements +copyWithZone: but none -copyWithZone:. The error message indicates that copyWithZone: has been sent do an instance of the class, not the class itself.

theObject is the local method's parameter.

- (NSString *) outputValue: (NSManagedObject *) theObject {...}

And you see in the debuggers output that it really is of that type. And it does have a property currency that is different from nil.

Any ideas? I am happy to provide more code but I don't know yet which sniplets you could be insterested in.

This is the general available SDK 6.1 based on current xcode and copiler versions, non of the currently circluating beta stuff.

Upvotes: 0

Views: 1229

Answers (1)

Martin R
Martin R

Reputation: 540055

From your NSLog output

<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>";
    ...

it seems that "currency" is a relationship to another entity, so

[theObject valueForKey:kFieldCurrency]

would return an object of that entity and not a string, as expected by the setCurrencySymbol: method.

Perhaps you want something similar to

[numberFormatter setCurrencySymbol:[theObject valueForKeyPath:@"currency.symbol]];

assuming that "symbol" is a string attribute of the "Currency" entity.

Upvotes: 3

Related Questions