I’m trying to set a property like so –
-interface:
@property (readwrite, assign) CGColorRef otherBallColor;
-someMethod:
CGColorRef ballColor = [UIColor colorWithRed:255.0/256.0 green:165.0/256.0 blue:239.0/256.0 alpha:1.0].CGColor;
[self setOtherBallColor:ballColor];
As soon as I try to access the value it crashes –
-someOtherMethod (drawRect in this case):
CGContextSetFillColorWithColor(context, otherBallColor);
But if in the “someMethod” I do –
CGColorRef ballColor = [UIColor blueColor].CGColor;
… it all works fine. Can anyone explain what’s going on?
Many thanks (PS, quite new to Objective-C, tho not programming in general)
You must retain returned CGColor, your [UIColor colorWith…] creates an auto-released instance, so, when it is out of scope (autoreleased I mean), corresponding CGColor is released as well.
I’d recommend you to use UIColor instead of CGColorRef if i is possible in this case.