views:

78

answers:

2

I'm getting a NSObject doesNotRecognizeSelector error when trying to set a property and I'm not sure why.

The error occurs on the first line of setWithNSColor. I'm a bit confused how a property that's properly synthesized could be not recognized.

@interface ScopeColor : NSObject {
NSString *colorIntegerString;
float redColor;
float greenColor;
float blueColor;
NSString *name;
}

@property (readwrite, assign) NSString *colorIntegerString;
@property (readwrite, assign) float redColor;
@property (readwrite, assign) float greenColor;
@property (readwrite, assign) float blueColor;
@property (readwrite, assign) NSString *name;

-(void)setWithNSColor:(NSColor *)inColor
{
    self.redColor=[inColor redComponent];
    self.greenColor=[inColor greenComponent];
    self.blueColor=[inColor blueComponent];
}
+3  A: 

Are you sure it is your class and not NSColor that is raising the exception? If the NSColor object does not belong to the NSCalibratedRGBColorSpace or NSDeviceRGBColorSpace asking for redComponent, etc. will raise an exception.

sbooth
Doh. I believe you're correct.
Wade Williams
A: 

Are you synthesizing redColor, greenColor, and blueColor somewhere outside of the included code? Also, primitive values (such as floats) don't need the assign keyword.

Ben Gottlieb
Correct me if I'm wrong, but it's redundant rather than wrong. Assign is the default.
Wade Williams
I didn't say "wrong", I said "don't need" :-) Since it's not an object, you don't need to specify, it can only be assign.
Ben Gottlieb
I'd also add that it's preferable to use `copy` for `NSString*` rather than `assign`
Abizern