I want to add some class methods to UIColor. I’ve implemented them and everything compiles fine, but at runtime I get the following error:
Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[UIColor colorWithHex:]: unrecognized selector sent to class 0x8d1d68’
Here’s the header file:
@interface UIColor (Hex)
+ (UIColor*) colorWithHex: (NSUInteger) hex;
@end
Here’s the implementation:
#import "UIColor+Hex.h"
@implementation UIColor (Hex)
+ (UIColor*) colorWithHex: (NSUInteger) hex {
CGFloat red, green, blue, alpha;
red = ((CGFloat)((hex >> 16) & 0xFF)) / ((CGFloat)0xFF);
green = ((CGFloat)((hex >> 8) & 0xFF)) / ((CGFloat)0xFF);
blue = ((CGFloat)((hex >> 0) & 0xFF)) / ((CGFloat)0xFF);
alpha = hex > 0xFFFFFF ? ((CGFloat)((hex >> 24) & 0xFF)) / ((CGFloat)0xFF) : 1;
return [UIColor colorWithRed: red green:green blue:blue alpha:alpha];
}
@end
I’ve found something about adding -all_load to the linker flags, but doing that gives the same result. This is on the iPhone, if it wasn’t clear.
Hm. After changing the build configuration to release and back to debug, it worked like a charm.
Strange.