iOS 5需要ARC桥接转换

Bil*_*Ray 1 xcode image ios automatic-ref-counting

我遵循一个教程,我不知道如何转换此代码,以使其免费运行,没有启用ARC的错误.

- (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;
Run Code Online (Sandbox Code Playgroud)

给我一个错误的唯一部分是(id)图像;

w = CGImageGetWidth((CGImageRef)hourHand.contents);
Run Code Online (Sandbox Code Playgroud)

(CGImageRef)minHand.contents); 给了我一个错误

谢谢

Lil*_*ard 16

你需要一个__bridge演员.

hourHand.contents = (__bridge id)image;
Run Code Online (Sandbox Code Playgroud)

w = CGImageGetWidth((__bridge CGImageRef)hourHand.contents);
Run Code Online (Sandbox Code Playgroud)

__bridge铸告诉ARC这一投不以任何方式影响对象的所有权.替代品是__bridge_retained__bridge_transfer,通常通过CFBridgingRetain()CFBridgingRelease()功能使用.