1

I'm making a graph, and I want to make a system for specifying the conditions to transition between nodes along an edge. I am unsure of what the method signature should look like, since different transitions will have different parameters.

So the 2 functions of interest are these:

-addEdge(NSString* firstState, NSString* secondState,NSString* edgeName, block (?))

-(bool)transition(NSString* edgeName, parameters (?) ... )

addEdge() passes in a block that defines the transition condition between firstState and secondState, and gives it a name.

transition() takes in a list of parameters and applies them to the block associated with the edge name.

What should the method signatures look like, in this case?

rurulu
  • 42
  • 5
  • Is `parameters` an array? How is `block` declared? – CrimsonChris Jun 24 '14 at 18:46
  • So, that is what I am wondering; I want block to take in arbitrary parameters that is presumably applicable to the specific edge. Something like [this](http://www.numbergrinder.com/2008/12/variable-arguments-varargs-in-objective-c/). I am unsure of what the declarations should look like to achieve this behaviour – rurulu Jun 24 '14 at 19:00
  • Declaring the block to take variable arguments is the easy part. _Using_ variable arguments is hard. http://www.numbergrinder.com/2008/12/variable-arguments-varargs-in-objective-c/ – CrimsonChris Jun 24 '14 at 19:09

2 Answers2

0

Blocks can accept variable arguments though accepting an NSArray is arguably simpler.

typedef void(^VarArgsBlock)(int argumentLength, ...);
CrimsonChris
  • 4,651
  • 2
  • 19
  • 30
0

You cannot declare a block with arbitrary parameters. But you always can add id parameter, which is whatever you want. It could be NSArray or object of some specific class that you've define, anything you want. Hence you don't need any varargs.

Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51