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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:55:37+00:00 2026-05-13T08:55:37+00:00

I am relatively new to Objective C and need some array help. I have

  • 0

I am relatively new to Objective C and need some array help.

I have a plist which contains a Dictionary and an NSNumber Array, with more arrays to
be added later on.

NSMutableDictionary *mainArray = [[NSMutableDictionary alloc]initWithContentsOfFile:filePath];

NSArray *scoresArray = [mainArray objectForKey:@"scores"];

I need to retrieve all the values from the array and connect them to 10 UILabels which
I’ve set up in interface builder. I’ve done the following to cast the NSNumber to a String.

NSNumber *numberOne = [scoresArray objectAtIndex:0];  
NSUInteger  intOne = [numberOne intValue];  
NSString *stringOne = [NSString stringWithFormat:@"%d",intOne];  
scoreLabel1.text = stringOne;

This seems a very long winded approach, I’d have to repeat the 4 lines above ten times to retrieve all the array values. Could I use a for loop to iterate through the array with all of the values converted to Strings at the output?

Any info would be greatly appreciated.

  • 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-13T08:55:38+00:00Added an answer on May 13, 2026 at 8:55 am
    // create NSMutableArray* of score UILabel items, called "scoreLabels"
    NSMutableArray *scoreLabels = [NSMutableArray arrayWithCapacity:10];
    [scoreLabels addObject:scoreLabel1];
    [scoreLabels addObject:scoreLabel2];
    // ...
    
    NSUInteger _index = 0;
    for (NSNumber *_number in scoresArray) {
        UILabel *_label = [scoreLabels objectAtIndex:_index];
        _label.text = [NSString stringWithFormat:@"%d", [_number intValue]];
        _index++;
    }
    

    EDIT

    I’m not sure why you’d want to comment out _index++. I haven’t tested this code, so maybe I’m missing something somewhere. But I don’t see anything wrong with _index++ — that’s a pretty standard way to increment a counter.

    As an alternative to creating the scoreLabels array, you could indeed retrieve the tag property of the subviews of the view controller (in this case, UILabel instances that you add a tag value to in Interface Builder).

    Assuming that the tag value is predictable — e.g., each UILabel from scoreLabel1 through scoreLabel10 is labeled with a tag equal to the values of _index that we use in the for loop (0 through 9) — then you could reference the UILabel directly:

    // no need to create the NSMutableArray* scoreLabels here
    NSUInteger _index = 0;
    for (NSNumber *_number in scoresArray) {
        UILabel *_label = (UILabel *)[self.view viewWithTag:_index];
        _label.text = [NSString stringWithFormat:@"%d", [_number intValue]];
        _index++;
    }
    

    The key to making that work is that the tag value has to be unique for the UILabel and must be something you can reference with -viewWithTag:.

    The code above very simply assumes that the tag values are the same as the _index values, but that isn’t required. (It also assumes the UILabel instances are subviews of the view controller’s view property, which will depend on how you set up your interface in Interface Builder.)

    Some people write functions that add 1000 or some other integer that allows you group types of subviews together — UILabel instances get 1000, 1001, and so on, and UIButton instances would get 2000, 2001, etc.

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

Sidebar

Ask A Question

Stats

  • Questions 314k
  • Answers 314k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Replace TaskAction was inserting Unicode characters while the rc… May 13, 2026 at 10:57 pm
  • Editorial Team
    Editorial Team added an answer Try NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot C:\Sites\mysite ServerName xx.xx.xx.xx </VirtualHost>… May 13, 2026 at 10:57 pm
  • Editorial Team
    Editorial Team added an answer There are two aspects to this question. Data migration Your… May 13, 2026 at 10:57 pm

Related Questions

Apple added the new IOSurface framework as part of the 10.6 Mac OS X
Note: I'm relatively new to Objective-C and am coming from Java and PHP. Could
My installation of XCode 3.2 has begun to exhibit some strange behaviour. When I
I'm not yet a fan of integrated development environments, but I'm trying to overcome
What experience have you had with introducing a Ribbon style control to legacy MFC

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.