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

  • SEARCH
  • Home
  • 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 4607118
In Process

The Archive Base Latest Questions

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

Objective-C, or Cocoa specifically, supports variadic arguments, like for example class the method on

  • 0

Objective-C, or Cocoa specifically, supports variadic arguments, like for example class the method on NSString +(NSString *)stringWithFormat:(NSString *)string, .....

Now, what I would like to know is if it is possible to follow that variadic argument must be at the end of the method, or can the method continue after that?

As an example, suppose I have the variadic method (with the appropriate macro),

- (void)setObjects:(id)obj, ... NS_REQUIRES_NIL_TERMINATION;

If I want to use it at a specific index, could I do something like this,

- (void)setObjects:(id)obj, ... NS_REQUIRES_NIL_TERMINATION atIndex:(int)index;

I’ve been trying, and this specific example doesn’t work, giving me an error message saying “Expected ‘;’ after method prototype”. Of course, I could shuffle the arguments around to make sure the variadic one is at the end, like this,

- (void)atIndex:(int)index setObjects:(id)obj, ... NS_REQUIRES_NIL_TERMINATION;

This certainly works, but to me it feels rather alien amidst the Cocoa naming conventions — which is a problem for me.

Thank you,

  • 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-22T00:39:30+00:00Added an answer on May 22, 2026 at 12:39 am

    Variadic arguments must be the last argument. This is because a method in Objective-C is really just an ordinary C function in disguise, and C doesn’t allow any arguments after a variadic argument either.

    The reason C doesn’t allow it has to do with the calling convention that C supports. When you call a variadic function, the number of variadic arguments is not actually known be the function at first. Different functions can then figure it out in different ways. In Objective C, terminating a variadic argument with nil is common. The printf function figures out how many arguments it’s passed based on the format string. Since the function doesn’t initially know how many variadic arguments there are, it has no way of knowing the memory location of an argument after the variadic argument list.

    Look up “C calling conventions” if you wish to know more.

    (Some consider this limitation to be a “wart” of the C language, which is fair. However, we are stuck with it due to the need for ABI compatibility. C++ has the same issue with variadic functions.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to write an Objective-C class without Cocoa or GNU's Object.h (for educational
How can I execute a terminal command (like grep ) from my Objective-C Cocoa
Are there any generally-accepted coding standards (naming, casting etc) that apply specifically to iPhone/Cocoa/Objective-C?
I have some experience of Objective-C/Cocoa programming on Mac and I'd like to start
I found an example of Objective-C/cocoa framework has the following code. int main() {
I'm just learning Objective-C/Cocoa programming for the Mac. All of the tutorials, books, blogs,
I'm a complete Xcode/Objective-C/Cocoa newbie but I'm learning fast and really starting to enjoy
So I finally dusted off my Objective-C/Cocoa books.. turns out they are nearly 7
Is there any centralized repository of useful Objective-C / Cocoa libraries as there is
What's the best way to throw an exception in objective-c/cocoa?

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.