Jens,
I understand your point and agree with it. I also followed Scott's suggestion and he's right that the first url that came up answered my question mostly.
While I was working I was a professional software engineer for 34 years and became quite proficient with all sorts of esoteric subjects related to my work. Now, however, I program as a hobby and just for the fun of it. Part of my enjoyment comes from investigating all sorts of esoteric subjects related to it. What this boils down to is that sometimes the "how" of doing something is what I am after.
This question came to me because I had written a method that took a var_arg list and used a rather pedantic switch statement to call it in the various ways I needed. It didn't take long to become dissatisfied with the switch statement so I declared an array with the various parameters in it and converted the method to take an array as its argument list.
And yet I wasn't really satisfied with this so I formulated the question and went in search of an answer. The result of the search Scott suggested answered the question but in a way that, to me, is no more satisfying than the switch statement was.
I found the NSSelectorFromString function and the various "performSelector" methods but these methods don't do the job.
I was hoping there might be some method using recursive macros to construct the arg list. On May 24, 2012, at 11:30 AM, Jens Alfke wrote: On May 24, 2012, at 6:43 AM, Scott Ribe wrote: Sure. Google "objective-c variadic args"
I don't think you read the OP's question carefully enough. That query is really too vague to be helpful, although looking at the top answer from Stack Overflow did turn up this comment:
Which I believe is true. (Or to be 100% accurate, I can imagine ways to do this but they involve nasty platform-dependent stack hackery, possibly even inline assembly. Don't go there.)
Charlie: In most cases, Cocoa methods that take varargs have equivalent methods that take parameters either as a va_list, as a C array, or as a Cocoa collection object. If you define your own methods that take varargs, you can similarly make alternatives. So there should always be workarounds to shoving an array into a "…".
—Jens
|