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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:51:00+00:00 2026-05-21T13:51:00+00:00

I am developing an iPhone application which has a lot of different cards, each

  • 0

I am developing an iPhone application which has a lot of different cards, each one of those represents a car. So, every card has some instance variables and one image. My class CarCard is loading data for each car from a .plist file. I want to make many instances in a loop so as to give different name to each instance. E.g:

CarCard *car1 = [[CarCard alloc] initWithSomeINfo: info];
....... *car2 ..........................................;

....... *carN ..........................................;

where N is the number of Cars. The problem is that I do not know what the number N is each time. So i have to make the instances in a loop, but i could not find how to give different names to instances.

  • 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-21T13:51:00+00:00Added an answer on May 21, 2026 at 1:51 pm

    An NSMutableArray of CarCard objects is a much better way to go. Instantiate it outside of your loop:

    NSMutableArray *cardArray = [[NSMutableArray alloc] init];
    

    then inside your loop you’ll add your objects:

    [cardArray addObject:car];
    

    Now you can access them by their indices:

    // Card 9, numbering starts at 0
    myCar = [cardArray objectAtIndex:8];
    

    Edited to add

    If you want to refer to the cards by their name instead of their position in the array and the names will be unique, you can use a dictionary and refer to the cards by name. Instantiate the dictionary outside of the loop:

    NSMutableDictionary *cardDictionary = [[NSMutableDictionary alloc] init];
    

    then inside the loop you’ll add your objects:

    [cardDictionary setObject:car forKey:cardName];
    

    Now you can access them by their names:

    // Card with the key named "card9"
    myCar = [cardDictionary objectForKey:@"card9"];
    
    // Card with the key named "monkey"
    myCar = [cardDictionary objectForKey:@"monkey"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to iPhone apps, I am developing one application which requires playing
I am developing iPhone application and In that application I've one TableViewController , and
I am developing an iPhone application which works perfectly when doing a build &
I am developing an iPhone application which will install few third party applications in
I am developing an iPhone application that persists data to a SQLite3 database. For
i am developing a iphone application in a view-based project,(not navigation) however i would
Coming up towards the end of developing an iPhone application and I'm wondering just
I’m interested in developing an iPhone application using Visual Studio and C#.NET on Windows
I'm in the process of developing my second iPhone application, and am looking for
I am currently developing a charting application (for the iPhone, although that is largely

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.