So the answer by trojanfoe is only partly correct.
There is a huge problem with doing that. When you create the NSValue
that way, you are copying the cpShape
struct, and getting it back out, you are copying it again. cpShape
structs are pretty much exclusively used by reference. Each time you copy it, you get a new reference to the new copy, and some of those copies exist on the stack and get destroyed silently and automatically. Very very bad.
Instead you want to create a NSValue
using [NSValue valueWithPointer:shape]
and get that pointer back using [value pointerValue]
. This way the NSValue is only storing a pointer to the original cpShape
.