I need to receive more than one variable Args in my method. But I don’t know how to do so.
For example:
(void)insertInTableOnAttributes:(id)fieldsNames, ... Values:(id)fieldsValues, ...;
sadly it appears a compiler error after the first (...) saying:
Expected ':' after method Prototype".
And in the implementation says:
Expected Method Body" in the same position (just after the first ...)
PD: I’m using Xcode 4.2.1.
You can’t do that. How would the generated code possibly know where one argument list ends and the next begins? Try to think of the C equivalent
The compiler will reject that for the same reason.
You have two reasonable options. The first is to provide a method that takes
NSArrays instead.The second is to use one varargs with a name-value pair, similar to
+[NSDictionary dictionaryWithObjectsAndKeys:]This one would be used like
The C analogy is actually quite accurate. An Obj-C method is basically syntactic sugar on top of a C method, so
is backed by a C method that looks like
except it doesn’t actually have a real name. This C function is called the
IMPof the method, and you can retrieve it using obj-c runtime methods.In your case of having arguments after a varargs, your
would be backed by an
IMPthat looks likeand since you cannot have any arguments after a varargs, this simply won’t work.