2

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

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
Fate Rowen
  • 77
  • 2
  • 8
  • The first answer to this question explains bridge casting fairly well http://stackoverflow.com/questions/6725558/cast-of-objective-c-pointer-type-nsstring-to-c-pointer-type-cfstringref-a – oltman Dec 29 '11 at 02:30
  • Also, if you understand pointers, the C++ `->` operator isn't anything fancy. `ballShape->e` is the equivalent of `(*ballShape).e`. – oltman Dec 29 '11 at 02:37
  • ARC is Objective C - why is this tagged C++ (or C)? – mmmmmm May 30 '12 at 18:58

1 Answers1

0

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

tia
  • 9,518
  • 1
  • 30
  • 44