Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6648729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:41:22+00:00 2026-05-26T00:41:22+00:00

On Objective-C, I can do something like: UIAlertView *av = [[UIAlertView alloc] initWith …

  • 0

On Objective-C, I can do something like:

UIAlertView *av = [[UIAlertView alloc] initWith ... otherButtonTitles:@"button1", @"button2", nil];

Can I make a method for myself which takes as an argument these parameters separed by a comma… And if so how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:41:23+00:00Added an answer on May 26, 2026 at 12:41 am

    Declare the method like this in your @interface:

    - (id)myObjectWithObjects:(id)firstObject, ... NS_REQUIRES_NIL_TERMINATION;
    

    Then in the @implementation you would define it like this:

    - (id)myObjectWithObjects:(id)firstObject, ...
    {
        va_list args;
        va_start(args, firstObject);
        for (id arg = firstObject; arg != nil; arg = va_arg(args, id))
        {
            // Do something with the args here
        }
        va_end(args);
    
        // Do more stuff here...
    }
    

    The va_list, va_start, va_arg and va_end are all standard C syntax for handling variable arguments. To describe them simply:

    • va_list – A pointer to a list of variable arguments.
    • va_start – Initializes a va_list to point to the first argument after the argument specified.
    • va_arg – Fetches the next argument out of the list. You must specify the type of the argument (so that va_arg knows how many bytes to extract).
    • va_end – Releases any memory held by the va_list data structure.

    Check out this article for a better explanation – Variable argument lists in Cocoa


    See also: “IEEE Std 1003.1 stdarg.h”


    Another example from the Apple Technical Q&A QA1405 – Variable arguments in Objective-C methods:

    @interface NSMutableArray (variadicMethodExample)
    
    - (void) appendObjects:(id) firstObject, ...; // This method takes a nil-terminated list of objects.
    
    @end
    
    @implementation NSMutableArray (variadicMethodExample)
    
    - (void) appendObjects:(id) firstObject, ...
    {
        id eachObject;
        va_list argumentList;
        if (firstObject) // The first argument isn't part of the varargs list,
        {                                   // so we'll handle it separately.
            [self addObject: firstObject];
            va_start(argumentList, firstObject); // Start scanning for arguments after firstObject.
            while (eachObject = va_arg(argumentList, id)) // As many times as we can get an argument of type "id"
                [self addObject: eachObject]; // that isn't nil, add it to self's contents.
            va_end(argumentList);
        }
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Objective-C you can say something like: NSArray *anArray = [NSArray arrayWithObjects:obj,obj2, nil]; In
In objective-c, how can I make something like well, I want you to run
In objective-c manual it is written that something like return [[[SomeClass alloc] init] autorelease];
In objective-c, I can do something like @interface MyViewController : UIViewController <UITextInputDelegate> to create
In the Modern Objective-C runtime, you can do something like this: @interface MyClass :
Objective : Make a progress bar where users can check how much of a
How can I execute a terminal command (like grep ) from my Objective-C Cocoa
How can I invoke a method at runtime on an Objective-C class when all
In C# I can write something like this: enum MyEnum : byte { Value1,
Ok... in Objective C you can new up a subclass from a static method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.