Amazon.com Widgets How can i create a twodimentional NSMutableArray an how can i access it?
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 04:25:12 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 15 - Numbers, Strings, and Collections
| | | |-+  How can i create a twodimentional NSMutableArray an how can i access it?
Pages: [1]   Go Down
Print
Author Topic: How can i create a twodimentional NSMutableArray an how can i access it?  (Read 661 times)
yelssorc
Newbie
*
Posts: 2






« on: August 26, 2009, 11:42:13 AM »

Hi,

in C i create an array: int a[10][10] = { ... };
and access it using a[1][5]=...;

How can i create a two- or moredimentional NSMutableArray in objective-c and how can i access it?

Thanks
Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #1 on: August 26, 2009, 12:38:28 PM »

Simply make an array with each element in the array another array:

Code: (Objective-C)
NSMutableArray  *matrix = [NSMutableArray arrayWithCapacity: 10];

// Add an array as each element of matrix

for ( int i = 0; i < 10; ++i )
    [matrix addObject: [NSMutableArray arrayWithCapacity: 10]];

...
// get 2nd row, 3rd column element from matrix

foo = [[matrix objectAtIndex: 1] objectAtIndex: 2];
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.