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
iOS 5 requires ARC bridged cast
提问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 __bridge
cast.
你需要一个__bridge
演员。
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.
该__bridge
铸告诉ARC这一投不以任何方式影响对象的所有权。替代方法是__bridge_retained
and __bridge_transfer
,它们通常通过CFBridgingRetain()
andCFBridgingRelease()
函数使用。