Search code examples
c++objective-cautomatic-ref-countingchipmunk

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):

// 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; I'm trying to link the data property of the ballShape object with the UIImageView object ball. If I turn off ARC processing this works fine, but with ARC I can't do this, getting the error:

"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? 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. Sorry in advance if this is a pretty basic question, but the "->" operator in C confuses and angers me. :)


Solution

  • If you just want to store pointer, it is correct as long as you keep your reference to your ball.