Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12367

Is there a way to cast a b2Body to an Objective-C object

I need to iterate through certain bodies. For that I want to add those bodies to an NSMurableArray. But as NSMutableArray accepts objective-c objects only, I need a way to cast b2Body to id. Trying [bodiesArray addObject:(id)body]; does not help.

Upvotes: 3

Views: 231

Answers (1)

B.S.
B.S.

Reputation: 21726

You can use NSValue's valueWithPointer

NSValue *bodyValue = [NSValue valueWithPointer:body];
[bodiesArray addObject:bodyValue];

and get your b2Body object back

b2Body *body = (b2Body*) [[bodiesArray objectAtIndex:0] pointerValue];

Upvotes: 6

Related Questions