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 6197767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:52:47+00:00 2026-05-24T03:52:47+00:00

this is really a newbie question, but it would help me to have a

  • 0

this is really a newbie question, but it would help me to have a better understanding of how Objective-c works. I have made use of UIActionSheet in a iOS app. Looking at documentation this is the relevant init method:

- (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

Where otherButtonTitles is said to be a comma separated list of NSString. In my mind this is correspondent to an NSArray, so with the intent of caushing a crash I tried:

NSArray *buttons = [NSArray arrayWithObjects:@"B1",@"B2",nil];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:buttons];

And then obviously the application crashed because of buttons NSArray.
This sounds so similiar to Java varargs, where in a class you can have something like:

public void myMethod(String... param) {...};

A legal call to this method is:

myClass.myMethod("x");
myClass.myMethod("x","Y");

I have a lot of methods in my iOS apps that made use of NSArray:

[myClass myMethod:[NSArray arrayWithObjects:....]];

And it would be very convenient for me to avoid alloc of NSArray but rather passing a comma separated list of NSString. How can I do that ? I mean, from the myMethod point of view, what type of param is received and how should it be considered ? For example how can I cycle trough an NSString ???

thanks

  • 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-24T03:52:47+00:00Added an answer on May 24, 2026 at 3:52 am

    As the king of Objective-c newbie as I am, here comes a little misundertanding for me. As pointed out by Graham, the method made indeed use of variable arguments. At first glance I completely missing this, the Java varargs notation has this equivalent in Objective-c:

    public void myMethod(String... var);
    -(void)myMethod:(NSString*)var,...;
    

    Infact if you take a look at UIActionSheet method signature it put exactly the same three dot notation in the part regarding other buttons:

    otherButtonTitles:(NSString *)otherButtonTitles, ...
    

    Also for dealing with variable arguments in objective-c I found a very useful link:

    http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html

    Coming to my question, I can safely rewrite all my methods by implementing the ‘three dot notation’, and throw away all the unnecessary NSArray.

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

Sidebar

Related Questions

This is probably a really newbie question (well, I'm pretty sure it is), but
This is probably a really stupid newbie-sounding question to you developer type people, but
Sorry fot his newbie question. But I really need a start on this one.
This is really a dumb newbie question, but I am still learning the ropes
this is going to be a total newbie question but I can't really do
This may be a newbie question. I've used javascript for years but have only
This is really a newbie question - but basically, how do I enable a
I'm really new to VSTO so sorry if this is a newbie question. I'm
This is a total newbie question, but I wonder if someone could assist with
I am newbie so my question can be really obvious, but I didn't find

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.