objective c - Enumerate method arguments -
is there way iterate on method arguments of objective-c methods? need lot of error checking in lot of methods , automate instead of checking each value comes in individually.
i know can done methods variable number of arguments. particularly looking way methods take fixed number of arguments.
- (void)mymethodwitharg1:(nsstring *)arg1 arg2:(nsnumber *)arg3 nserror:(nserror **)err { // arguments array nsarray *args; // ??? (id arg in args) { // stuff args .... } }
you try following.
- (void)mymethodwitharg1:(nsstring *)arg1 arg2:(nsnumber *)arg3 nserror:(nserror **)err { nsarray *args = [[nsarray alloc] initwithobjects:arg1, arg2, err, nil]; for(id arg in args) { if(arg) { // code want each arg here. } } } there nothing special going on here happening initializing nsarray objects objects being arguments, once in for loop checking arg , not nil or null. when in for loop again ever want argument , determine is.
if isn't looking please comment , amend best possible.
Comments
Post a Comment