Can you store multiple methods in one selector?

I have a mysterious program in which you put the blocks in the correct order to try to complete the puzzle. and when you are done, you can press the play button, and then the program will force the little person to walk along your blocks in the places where your blocks are. Therefore, if you put one block up, one block to the right, one block down, and then press the play button that the call will call, call the methods up, move right, lower it down.

When my program starts and tries to figure out which methods to call and in what order, I need to keep these methods in order when the program finds them, basically I can not get the program to call the methods right right when it finds out which methods to call or else the guy moving on the blocks will move lightning fast, I want to save the methods in some methods of the array (which I would think as a selector of some kind), so that I can call each method for a certain period of time after my pr gram found everything he was going to do.

my normal program now looks something like this.

if(random requirements)
[self moveUp]

else if(random requirements)
[self moveDown]

else if (random requirements)
[self moveRight]

else if(random requirements)
[self moveLeft]

well, I'd rather it look something like this.

if(random requirements)
SEL selector addMethod:[self moveUp]

else if(random requirements)
SEL selector addMethod:[self moveDown]

else if (random requirements)
SEL selector addMethod:[self moveRight]

else if(random requirements)
SEL selector addMethod:[self moveLeft]

this is obviously not the real syntax, but can you understand what I'm looking for?

+5
source share
1

, - . - NSMutableArray , .

NSMutableArray *selectorNames = [NSMutableArray array];
if(random requirements)
    [selectorNames addObject:NSStringFromSelector(@selector(moveUp))];
if(random requirements)
    [selectorNames addObject:NSStringFromSelector(@selector(moveDown))];
...
for (NSString *selectorName in selectorNames) {
    SEL nextSelector = NSSelectorFromString (selectorName);
    // Now you can invoke your selector
}

, , . , .

+8

All Articles