Box2d(c ++で記述されている)用のObjectiveCラッパーを実装しています。b2Bodyは、ラッパーB2Bodyへの参照をuserDataフィールドに保持します。GetUserDataはvoid*を返します。私は現在、B2BodiesをB2Worldから取り出すための高速イテレーションを実装しています。
以下に示す行で、互換性のないタイプ「B2Body*」から「ID」への割り当てエラーが発生します。なんで?
#import "B2Body.h"
#import "B2World.h"
#import "Box2d.h"
@implementation B2World
-(id) initWithGravity:(struct B2Vec2) g
{
  if (self = [super init])
  {
    b2Vec2 *gPrim = (b2Vec2*)&g;
    _world = new b2World(*gPrim);
  }
  return self;
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len;
{
  if(state->state == 0)
  {
    state->mutationsPtr = (unsigned long *)self;
    state->extra[0] = (long) ((b2World*)_world)->GetBodyList();
    state->state = 1;
  }
  // pull the box2d body out of extra[0]
  b2Body *b = (b2Body*)state->extra[0];
  // if it's nil then we're done enumerating, return 0 to end
  if(b == nil)
  {
    return nil;
  }
  // otherwise, point itemsPtr at the node's value
  state->itemsPtr = ((B2Body*)b->GetUserData()); // ERROR
  state->extra[0] = (long)b->GetNext();
  // we're returning exactly one item
  return 1;
}
`
B2Body.hは次のようになります:#import
@interface B2Body : NSObject
{
  int f;
}
-(id) init;
@end