View Full Version : unrecognized selector sent to instance with Coredata and Category of NSMangedObject

Sep 4, 2012, 08:19 PM

I experience a very weird behavior and I am at wit's end.
I am subclassing NSManagedObject that I generated by xcode. Since I might change the schema I used the recommended approach of not adding code to the subclass, but through a category (I am calculating new attributes based on other attributes that are in the database).

Here is my code:

.h file of Category file:

#import "DiamondDetails.h"

@interface DiamondDetails (DiamondImageCategory)
-(UIImage *) diamondUIImage;
-(UIImage *) certificateUIImage;

.m file of Category file:

@implementation DiamondDetails (DiamondImageCategory)

-(UIImage *) diamondUIImage {
NSLog(@"Diamond image called on diamond details");
if (self.diamondImage != nil)return [UIImage imageNamed:self.diamondImage];
else {
NSLog(@"No image. Returning nil...");
return nil;

-(UIImage*) certificateUIImage {
if (self.certificateImage != nil)return [UIImage imageNamed:self.certificateImage];
else {
NSLog(@"No cert image. Returning nil...");
return nil;

Now, I am trying to access the new attributes like this:

UIImage * img = [d.diamondDetails diamondUIImage];

Now, it seems everything works great! xCode recognizes the new attributes, so it autocompletes - when I start type "dia..." I can choose from the popup diamondUIImage.

But when I run the app, I keep get a sigabrt error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DiamondDetails diamondUIImage]: unrecognized selector sent to instance 0x7f56db0'

Can't figure out why, been searching for 3 hours already. Probably I missing something obvious, but any help will be greately appreciated

Sep 4, 2012, 09:06 PM
The only thing jumping at me is the fact that the d in Diamond is capital in the error message, suggesting that you're making a call for diamondUIImage to the class rather than an instance at some point. Are you certain that the app is crashing on the one line you gave us and not somewhere else? Can you set a breakpoint just before the line and verify that the app crashes when it executes that exact line?

Sep 4, 2012, 09:23 PM
To eliminate the obvious: did you include DiamondDetails+DiamondImageCategory.h?

Sep 5, 2012, 05:28 AM
Yes, I included the #import "DiamondDetails+DiamondImageCategory.h"
Also, I am sure this is the line where i crash because 1: I put an NSLog message before that line. 2. When I comment out the line the app runs fine. And 3. xcode put the sig signal SIGABRT green line after it crash on this line.

Sep 5, 2012, 05:39 AM
We're missing details here. What is d an instance of ?

UIImage * img = [d.diamondDetails diamondUIImage];

This line of code. let's break it down. You have an object instance named "d". It is an instance of some class. We don't know about this class, you haven't told us what it is.

On this instance, you're accessing the property diamondDetails. We don't know how this is defined, what type of object it stores. Going by your code though, it should be something like this :

@property (nonatomic,retain) DiamondDetails * diamondDetails;

Does the class that "d" is an instance of have such a property ?

To eliminate the obvious: did you include DiamondDetails+DiamondImageCategory.h?

That would give him compile time errors, he's getting a runtime error.

Sep 5, 2012, 05:40 AM
I just figured this out....

I guess at some point I regenerated the NSMangedObject subclass, and deleted the old ones. The DiamondDetails+DiamondImageCategory.m file wasn't in the Compile Sources in the Build Phase