ObjC: Put the logic in a variable and queue that variable in an array ... daydreaming?

I am trying to translate the following JS code in ObjC; It basically defines the function and stores it in an array for later execution:

var logic = function() { me.removeNode(node); } this.queue.push(logic); 

My ObjC port contains a method: -(void)removeNode:(AbstractNode*)node and I'm stuck ... I would just like to queue this method using the specified node argument ...

edit: I read about selectors. It is still blurring, but it can help. Somehow. Or not?

Is this possible, or do I need to find a workaround :-)? Thanks!

The solution to this is thanks to the community:

 // Queue declaration NSMutableArray *IRQ = [[NSMutableArray array] retain]; // Add logic to the queue for delayed execution: [IRQ addObject:^{ NSLog(@"thanks for the help!"); } ]; // Call later for (int i = 0; i < [IRQ count]; i++){ void (^delayedCall)(void) = [IRQ objectAtIndex:i]; delayedCall(); } 
-one
source share
3 answers

Use block:

 [queue addObject:^{ [me removeNode:node]; }]; 

Here's a brief introduction to the blocks . This is the equivalent of anonymous Objective-C functions.

+5
source

I believe you should do this with function pointers. If your callback returns the same type and set of arguments, you should be able to write common code to call

+1
source

You can also use the NSInvocation class.

+1
source

All Articles