c - How to send optional arguments to another function/method? -
I have a named initializer with optional arguments (similar to the following code), and I want to make an autorelge method by calling I am this Is there any way to do this?
@Interface MyObject: NSObject - (id) initWithArgs: (id) firstArg, ...; + (Id) objectWithArgs: (id) firstArg, ...; @end @implementation MyObject - (id) initWithArgs: (id) firstArg, ... {ifF! FirstArg ||! [Super init]) {return nil} va_list argList; Va_start (argist, first light); Id currentObject = firstArg; Do {NSLog (@ "% @", current object); } While ((currentObject = va_arg (argList, id)) = zero; Va_end (argList); Self return; } + (Id) objectWithArgs: (ID) firstArg, ... {// Return [[MyObject alloc] initWithArgs: firstArg, ...] autorelease]; } @end
You can not do this See. The closest thing is that you can create two versions of your functions, which takes the verge ( ...
), and which takes a va_list
to make the Vergars version duplicate To avoid code, the va_list
version can pass through the job:
@interface MyObject: NSObject - (id) initWithArgs: (id) firstArg, ... ; - (id) init: (id) firstArg withVaList: (va_list) args; + (Id) objectWithArgs: (id) firstArg, ...; + (Id) object: (id) firstArg withVaList: (va_list) args; @end @implementation MyObject - (id) initWithArgs: (id) firstArg, ... {va_list args; Va_start (RGS, First Green); ID result = [self init: firstArg withVaList: args]; Va_end (args); Return result; } - (id) init: (id) firstArg withVaList: (va_list) args here is the real init: while ((id RGR = args, id)) {// ...}} + (id ObjectWithArgs: (id) firstArg, ... {va_list args; Va_start (RGS, First Green); ID result = [MyObject object: firstArg withVaList: args]; Va_end (args); Return result; } + (Id) object: (id) first order Vidyalist: (va_list) args {return [MyObject alloc] init: firstArg withVaList: args] autoresphere]; } @end
Comments
Post a Comment