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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:19:31+00:00 2026-06-14T20:19:31+00:00

Looked around for a while and couldn’t find an answer to this, but it

  • 0

Looked around for a while and couldn’t find an answer to this, but it seems like a pretty simple thing. I want to create an NSArray that has room for 100 objects (Doors) and then just loop through to create a new door for each index in the array. I couldn’t find a way to do this without manually writing the code for 100 new doors when I init the NSArray. I know I could do this by just creating an NSMutableArray and using addObject but I’ve heard NSArrays are much faster and I’d like to know how to do this for future reference.

Here’s what I’m basically trying to do:

NSArray *doors = [[NSArray alloc]init]; //with size 100?
for (int i = 0; i < [doors count]; i++)
    [[doors objectAtIndex:i] = [[Door alloc]init]];
  • 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-14T20:19:32+00:00Added an answer on June 14, 2026 at 8:19 pm

    if you are going to add objects to an array inside of a loop, then NSMutableArray is the correct object to use.

    To create 100 doors:

    NSMutableArray *doors = [NSMutableArray new];
    for (int i=0; i < 100; i++){
        [doors addObject:[[Door alloc]init]];
    }
    

    Now you have an mutable array with 100 Door Objects.
    If you have no need to later modify the array, you can convert it back to
    an immutable array for processing like this:

    NSArray *newDoorList = [NSArray arrayWithArray:doors];
    

    There may be some minor performance hits between mutable and non mutable arrays, but you will not notice them with just a few hundred objects – at least that has been my experience.

    hope that helps. good luck.

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

Sidebar

Related Questions

I looked around and couldn't find it! Maybe I didn't look hard enough,but this
I looked around but haven't found an answer to this. I have a CentOS
I've looked around for a solution but it seems this is not a common
I've looked around on SO but I couldn't find any similar question. After opening
I've looked around the current answers for similar questions but still couldn't find the
I have looked around on Google and StackOverflow for the answer to this question,
I've looked around but have yet to find a great solution the the following
I've looked around and couldn't find XOR functionality for ByteArrays in Actionscript 3. Can
I've looked around at a few different postings but haven't been able to find
Hi I apologize if the answer for this is somewhere else. I looked around

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.