I'm writing an iOS game that has configurable waves of enemies. I have one generic wave class that can be configured with the enemies, etc.
When a wave is started, I'd like to have a callback method for running custom code every level. I've been reading that objective-c doesn't have a way to define inline classes or anonymous functions, but I'd really like to avoid creating a separate header/class for every callback I need to use - mainly because the callbacks will only be a few lines.
In java, I'd do this:
wave.addCallback( new WaveCallback(){
public void onStart(){
// do some stuff
}
});
In iOS, I have this:
Wave *wave1 = [[Wave alloc] init];
[wave1 addEnemy:@"BasicSpaceship"];
// need to tell the wave to execute a few lines of code when started
[waves addObject:wave1];