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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:29:37+00:00 2026-06-13T04:29:37+00:00

Possible Duplicate: Objective C Equivalent of PHP’s Variable Variables I have created a method

  • 0

Possible Duplicate:
Objective C Equivalent of PHP’s “Variable Variables”

I have created a method in objective C which looks like this:

- (void) startBuildingXArray: (NSMutableArray *) arrayName:(int) senderID;

BUT, here is the tricky part. The particular arrayName argument depends on what the senderID is. Specifically, each arrayName has a number at the end of it (i.e. array1, array2, etc.) that matches the senderID in this method. Is there a way to dynamically add in an integer to the end of array name as a parameter? Or an entirely different and better way to yield the same result?

In other words, what I want to create is this sort of a situation:

- (void) startBuildingXArray: (NSMutableArray *) arrayName+(senderID):(int) senderID;

Of course that is not in any way valid code, I’m just trying to demonstrate what I want to happen. Can anyone suggest any sort of solution?

  • 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-13T04:29:38+00:00Added an answer on June 13, 2026 at 4:29 am

    You’re lucky: Objective-C is a dynamic language, so you can create selectors (method names) at runtime and also add corresponding implementation functions to them. Let’s assume you have already implemented these methods (for example, from startBuildingXArray:arrayName1: to ...arrayName9: etc.), and you’re looking for a way to call them depending on the integer ID:

    - (void)callMethodWithParam:(NSMutableArray *)parm ID:(int)ident
    {
        // get the selector name and the selector
        char zelektor[128];
        snprintf(zelektor, sizeof(zelektor), "startBuildingXArray:arrayName%d:", ident);
        SEL realSel = sel_getUid(zelektor);
    
        // Alternatively you can use Foundation as well:
        /*
        NSString *zelektor = [NSString stringWithFormat:@"startBuildingXArray:arrayName%d:", ident];
        SEL realSel = NSSelectorFromString(zelektor);
         */
    
        // Grab a function pointer to the implementation corresponding to the selector
        IMP imp = class_getInstanceMethod([self class], realSel);
    
        // and call the function pointer just obtained
        imp(self, realSel, parm, ident);
    }
    

    If you want to mass-create methods with names like this, you can use a similar approach but use the class_addMethod() Objective-C runtime function instead.

    However, this is a hack. I’d rather suggest you use one function and implement its task depending on the integer identifier that is passed in.

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

Sidebar

Related Questions

Possible Duplicate: Objective C Equivalent of PHP’s Variable Variables I have a UIButton action,
Possible Duplicate: Objective C Equivalent of PHP's “Variable Variables” I'm studding Objective-C and have
Possible Duplicate: Objective C Equivalent of PHP’s Variable Variables Today in one of my
Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Possible Duplicate: Global Variables in Cocoa/Objective-C? problem with declare a global variable in objective
Possible Duplicate: Global int variable objective c I would like to create a global
Possible Duplicate: Method overloading in Objective-C? Is method overloading not possible. I have two
Possible Duplicate: How to create variable argument methods in Objective-C Variable number of method
Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Possible Duplicate: Objective-c create variables in a loop I have 10 UILabels, for the

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.