Example of Unknown Multi Params Function


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //this is the way of passing multiple params
  2. +(NSInteger) writeWithFormat: (NSString*) formatString, ... {
  3. va_list va; //this will contain the list of parameters
  4. NSInteger length;
  5. //get all args, but last writen arg thats formatString.
  6. va_start(va, formatString);
  7. //string with format plus all arguments
  8. NSString* str =[ [ NSString alloc ] initWithFormat:formatString arguments:va ];
  9. va_end(va); //finish the parsing of arguments
  10. printf("%s\n",[ str UTF8String ]); //output to the console
  11. length = [ str length ]; //know the lenght of the string in characters
  12. [ str release ]; //relase the string
  13. return length; //return the amount of characters writen to the console
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.