Question

Is it possible to pass an objective c class (or maybe the notation is interface?) as message argument? Something like this:

-(void) f:(Class) c
{
  [c message];
}

To be more specific I want to call the following line:

[[CCDirector sharedDirector] replaceScene:[CCTransitionCrossFade transitionWithDuration:0.5f scene:[SceneDefence scene]]];

But I want SceneDefence to be a variable. I want to be able to call either SceneDefence or SceneAttack. The next scene will be stored in an instance variable in the init method, to later be used when the scene shall be changed.

Was it helpful?

Solution

Yes you had it correct, you just need to call the class method class.

-(void) f:(Class) c
{
    [c message]; //message will need to be a class method
}

...
   [myclass f:[SceneDefence class]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top