iOS 5需要ARC桥接转换

时间:2012-03-02 01:49:12

标签: ios xcode image 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;

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

另外

w = CGImageGetWidth((CGImageRef)hourHand.contents);

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

由于

1 个答案:

答案 0 :(得分:15)

您需要__bridge演员。

hourHand.contents = (__bridge id)image;

w = CGImageGetWidth((__bridge CGImageRef)hourHand.contents);

__bridge演员告诉ARC,此演员表不会以任何方式影响对象的所有权。替代方案为__bridge_retained__bridge_transfer,通常通过CFBridgingRetain()CFBridgingRelease()函数使用。