简体   繁体   English

ARC不允许对Objective-C指针进行隐式转换

[英]Implicit conversion of an Objective-C pointer is disallowed with ARC

I'm playing around with this Chipmunk Tutorial and I'm running into a problem with the following code (in section 5): 我正在玩这个Chipmunk教程,并且遇到了以下代码的问题(在第5节中):

// Create our shape associated with the ball's body    
cpShape *ballShape = cpCircleShapeNew(ballBody, 20.0, cpvzero);  
ballShape->e = 0.5; // Elasticity  
ballShape->u = 0.8; // Friction  
ballShape->data = ball; // Associate with out ball's UIImageView  

In the final line ballShape->data = ball; 在最后一行中,ballShape-> data = ball; I'm trying to link the data property of the ballShape object with the UIImageView object ball. 我正在尝试将ballShape对象的data属性与UIImageView对象ball链接。 If I turn off ARC processing this works fine, but with ARC I can't do this, getting the error: 如果我关闭ARC处理,则可以正常工作,但是使用ARC无法做到这一点,并得到以下错误:

"Implicit conversion of an Objective-C pointer to 'cpDataPointer' (aka 'void *') is disallowed with ARC"

Since ballShape is a pointer, and the original object has a data property, is there any way I can assign the ball object to that property and make ARC happy? 由于ballShape是一个指针,并且原始对象具有data属性,是否有任何方法可以将ball对象分配给该属性并使ARC满意? I'm trying the following code: 我正在尝试以下代码:

ballShape->data = (__bridge cpDataPointer)ball; // Associate with out ball's UIImageView  

This makes the error vanish but is this the correct fix for this problem? 这将使错误消失,但这是否是解决此问题的正确方法? I've looked at Apple's ARC documentation but a lot of it is pretty much over my head at the moment. 我看过Apple的ARC文档,但此刻很多东西已经超出了我的脑海。 Sorry in advance if this is a pretty basic question, but the "->" operator in C confuses and angers me. 如果这是一个非常基本的问题,请提前抱歉,但是C中的“->”运算符使我感到困惑和愤怒。 :) :)

如果您只想存储指针,那么只要保持对ball的引用就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM