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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:01:03+00:00 2026-05-24T12:01:03+00:00

I am working on a small isometric engine for my next iPhone game. To

  • 0

I am working on a small isometric engine for my next iPhone game. To store the map cells or tiles I need a 2 dimensionel array. Right now I am faking it with a 1-dimensionel, and it is not good enough anymore.

So from what I have found out looking around the net is that in objective-c I need to make an array of arrays.
So here is my question: How do I dynamicly create arrays at runtime based on how many map-rows I need?

The first array is easy enough:

NSMutableArray *OuterArray = [NSMutableArray arrayWithCapacity:mapSize];

now I have the first array that should contain an array for each row needed.
Problem is, it can be 10 but it can also be 200 or even more. So I dont want to manually create each array and then add it. I am thinking there must be a way to create all these arrays at runtime based on input, such as the chosen mapsize.

Hope you can help me
Thanks in advance
Peter

  • 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-24T12:01:04+00:00Added an answer on May 24, 2026 at 12:01 pm

    The whole point of NSMutableArray is that you don’t care. Initialize both dimensions with an approximate size and then add to them. If your array grows beyond your initial estimate the backing storage will be increased to accomodate it. This counts for both your columns (first order array), and rows (second order array).


    EDIT

    Not sure what you meant in your comment. But this is one way to dynamically create a 2-dimensional mutable array in Objective-C.

    NSUInteger columns = 25 ; // or some random, runtime number
    NSUInteger rows = 50;     // once again, some random, runtime number
    
    NSMutableArray * outer = [NSMutableArray arrayWithCapacity: rows];
    
    for(NSUInteger i; i < rows; i++) {
        NSMutableArray * inner = [NSMutableArray arrayWithCapacity: columns];
        [outer addObject: inner];
    }
    
    // Do something with outer array here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a small game engine. One of the features of it is
I'm working on a small templating engine, and I'm using DOMDocument to parse the
Im working on a small graphics engine project that and I want to it
Im working on a small project which has a textarea and i need help
I'm working on a small game and I'm having problems changing my Activity's content
I'm working on a small and simple XNA game and I'm noticing I'm spending
I am currently working in small chat app in iPhone. I am call to
I'm working in small app for iPhone which uses openGL. The app is supposed
is there any small working program for recieving from and sending data to client
I've been quite used to working on small projects which I coded with 1,000

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.