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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:42:40+00:00 2026-05-27T08:42:40+00:00

I have a variable name referencing question for the Objective C gurus out there.

  • 0

I have a variable name referencing question for the Objective C gurus out there.

Lets say I have 6 UILabels on a form, the are setup with properties naming them myLabel1 – myLabel6

I would like to go through a for loop and populate these with something depending on the loop but im unsure how to specifiy the for loops variable and make it part of the labels name.

Here is what I would like to do:

for (int LP = 0; i <5)
{

    labelLP.text = [NSString stringWithFormat:@"My label number:%d", LP};
}

What im not sure of is how to reference the label and append the LP int and use it in my loop. I’m sure there is a way to do this just not sure how.. Anyone??

  • 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-27T08:42:40+00:00Added an answer on May 27, 2026 at 8:42 am

    I don’t think you can create variable names on the fly, at least not trivially.

    You could always use a switch case inside your loop:

    for (int i=0; i<5; i++) {
    
        switch(i) {
    
            case 1:
                myLabel1.text = [NSString stringWithFormat:@"My label number: %d", i];
                break;
            case 2:
                myLabel2.text = [NSString stringWithFormat:@"My label number: %d", i];
                break;
            ...
            ...
        }
    }
    

    You could also store your labels in an array, and loop through that array.

    The important point is not to get fixated about the variable names, but to think about why you need your objects and how to get them.

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

Sidebar

Related Questions

Let's say I have a variable's name stored in another variable: myvar=123 varname=myvar Now,
Lets say I have a variable called $file and the for loop: for($i=1; $i
I have a long variable name in one of my models xxxx_xxxx_xx_xxxxxxxx is there
I have just discovered a variable name that is misspelled. If it were hidden
I've been have trouble understand this problem. If I change the variable name fifthViewController
I have a variable which has the directory path, along with the file name.
I have a string variable that represents the name of a custom class. Example:
I have the following variable that accepts a file name: var xtr = new
I have Man class which also has 2 variable : description and name. At
How can I retrieve a bash variable value if I have the variable name

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.