Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 requires ARC bridged cast

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

like image 635
BillyRay Avatar asked Dec 02 '25 05:12

BillyRay


1 Answers

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.

like image 78
Lily Ballard Avatar answered Dec 03 '25 22:12

Lily Ballard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!