xcode iOS 5 需要 ARC 桥接转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9526923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:29:36  来源:igfitidea点击:

iOS 5 requires ARC bridged cast

iosxcodeimageautomatic-ref-counting

提问by BillyRay

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.

我正在学习教程,但我不确定如何转换此代码以使其在启用 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;

The only part that is giving me an error is the (id)image;

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

Also

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

(CGImageRef)minHand.contents); gives me an error

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

Thanks

谢谢

回答by Lily Ballard

You need a __bridgecast.

你需要一个__bridge演员。

hourHand.contents = (__bridge id)image;

and

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

The __bridgecast tells ARC that this cast doesn't affect the ownership of the object in any way. The alternatives are __bridge_retainedand __bridge_transfer, which are generally used via the CFBridgingRetain()and CFBridgingRelease()functions.

__bridge铸告诉ARC这一投不以任何方式影响对象的所有权。替代方法是__bridge_retainedand __bridge_transfer,它们通常通过CFBridgingRetain()andCFBridgingRelease()函数使用。