Im following a tutorial and I'm not sure how to convert this code to get it to run free without errors with ARC enabled.
- (void)setHourHandImage:(CGImageRef)image
{
if (image == NULL) {
hourHand.backgroundColor = [UIColor blackColor].CGColor;
hourHand.cornerRadius = 3;
}else{
hourHand.backgroundColor = [UIColor clearColor].CGColor;
hourHand.cornerRadius = 0.0;
}
hourHand.contents = (id)image;
The only part that is giving me an error is the (id)image;
Also
w = CGImageGetWidth((CGImageRef)hourHand.contents);
(CGImageRef)minHand.contents); gives me an error
Thanks
You need a __bridge cast.
hourHand.contents = (__bridge id)image;
and
w = CGImageGetWidth((__bridge CGImageRef)hourHand.contents);
The __bridge cast tells ARC that this cast doesn't affect the ownership of the object in any way. The alternatives are __bridge_retained and __bridge_transfer, which are generally used via the CFBridgingRetain() and CFBridgingRelease() functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With