Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

roeik

macrumors member
Original poster
Dec 25, 2008
80
0
Hi,

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:

Code:
#import "DiamondDetails.h"

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

.m file of Category file:

Code:
@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:
Code:
 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
 
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?
 
To eliminate the obvious: did you include DiamondDetails+DiamondImageCategory.h?
 
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.
 
We're missing details here. What is d an instance of ?

Code:
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 :

Code:
@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.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.