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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:46:48+00:00 2026-06-07T01:46:48+00:00

I have created a method that accept variadic arguments like – (NSDictionary *) getImagePixelsAtLocation:

  • 0

I have created a method that accept variadic arguments like

- (NSDictionary *) getImagePixelsAtLocation: (int) locations,...NS_REQUIRES_NIL_TERMINATION

but when I send message to this class method, the value of locations variable in called method is 0 (it does not matter how many arguments I pass).

The method receives scalar data types. My question is: Can we pass scalar variable to a method as variadic arguments? If yes, what am I doing wrong?

The method definition is:

- (NSDictionary *) getImagePixelsAtLocation: (int) pixel1,...
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    va_list args;
    va_start(args, pixel1);

    //processing logic


    va_end(args);
} 

This is how I am sending message:

[HSImageProcessing getImagePixelsAtLocation:1,2,nil];
  • 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-06-07T01:46:50+00:00Added an answer on June 7, 2026 at 1:46 am

    Actually, there is one glaringly obvious flaw in your code there: when a variadic function is nil-terminated, the accepted type must be an object. You cannot compare an int to nil or NULL, or [NSNull null], which defeats the purpose of nil-termination, and effectively defeats all chances of iteration using the standard for and for-in loops. In addition, NSDictionary isn’t too happy about storing non-object types, and will happily make the compiler complain. I’ve rewritten it to accept NSNumber*, and output a dictionary of numbers.

    - (NSDictionary*) getImagePixelsAtLocation: (NSNumber*) pixel1,...
    {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        va_list args;
        va_start(args, pixel1);
    
        //processing logic
        for (NSNumber* arg = pixel1; arg != nil; arg = va_arg(args, NSNumber*)) {
            [dict setObject:arg forKey:[NSString stringWithFormat:@"%i", [arg intValue]]];
        }
    
        va_end(args);
        return dict;
    }
    

    All it takes is a little bit of extra code on your part to get that very same call working as well:

    [self getImagePixelsAtLocation:[NSNumber numberWithInt:1],[NSNumber numberWithInt:2],nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a method that should ideally take a single Account object and
I have created a custom method that will return unique items, together with the
I have created a new method in one of the project's controllers that it
I have created a gem that adds a new method to the class ActiveRecord::Base.
Currently I have created a ABCFactory class that has a single method creating ABC
I have a winforms application and I am trying to create a method that
I have a method that creates a local textfield and pops up the keyboard
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have created one service in my grails application. in that service 25 methods
I have a method CreateAccount(...) that I want to unit test. Basically it creates

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.