3

It is possible to have a method in this manner:

[obj mergeObjs:obj1,obj2,obj3,nil];

Or have a method in this manner:

[obj mergeObjs:obj1,obj2...obj(n),nil usingBlocks:blk1,blk2,blk3....blk(m),nil];

where n may or may not be equal to m.

Basically multiple variable argument lists in a single method declaration. ?

This is not a potential answer:

[obj merge:[NSArray arrayWithObjects:[NSArray arrayWithObjects:...,nil],[NSArray arrayWithObjects:...,nil]...,nil]];

Thanks in advance.

Here is the link i found for Single Variable Argument Lists:

http://developer.apple.com/library/mac/#qa/qa1405/_index.html How to create variable argument methods in Objective-C

Community
  • 1
  • 1

3 Answers3

5

You can't achieve this with a variable length argument list, but have you considered just passing two arrays?

[obj mergeObjs:(NSArray*)objs usingBlocks:(NSArray*)blocks];

Modern versions of clang (the Objective C compiler used by recent Xcode releases) even support NSArray literals

[instance mergeObjs:@[obj1, obj2, obj3] usingBlocks:@[^{}, ...]];

(Of course, making sure to copy your blocks appropriately for insertion into an NSArray).

Adam Wright
  • 48,938
  • 12
  • 131
  • 152
4

No. Message dispatch boils down to a call to objc_msgSend() (or one of its variants). That follows the C calling convention and there's no way to express the multiple variable argument lists in that convention.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
0

Concluding based on the responses & a serious loss of hair - It it not possible to have 2 variable argument lists in a method declaration.

The purpose of having mulit-Variable-argument-list was to provide more readability in my context.

Will make do with Arrays... Sigh!!.