iphone - Initialize 2 dim array NSMutableArray -



iphone - Initialize 2 dim array NSMutableArray -

for c init array this:

nsinteger x[3][10]; works.

below have 1 dim array works. move of 2 dim array, how init it? in other words take code below , create work 2 dimensions.

nsmutablearray *srdata; srdata = [[nsmutablearray alloc] init]; nsmutabledictionary *srrow; srrow = [[nsmutabledictionary alloc] init]; [srrow setobject:@"read" forkey:@"descr"]; [srrow setobject:@"read2.png" forkey:@"img"]; [srrow setobject:@"read codes" forkey:@"det"]; [srdata addobject:srrow] ; [srrow release];

in objective-c, have have array of arrays sec dimension. knowledge, there no shorthand, you're stuck doing following:

nsmutablearray *firstdimension = [[nsmutablearray alloc] init]; (int = 0; < rows; i++) { nsmutablearray *seconddimension = [[nsmutablearray alloc] init]; [firstdimension addobject:seconddimension]; }

so add together other objects (in case, nsmutabledictionarys) seconddimension array. usage like:

[[firstdimension objectatindex:0] objectatindex:0];

edit

full code example:

nsmutablearray *srdata = [[nsmutablearray alloc] init]; //first dimension nsmutablearray *srrow = [[nsmutablearray alloc] init]; //second dimension [srdata addobject:srrow]; //add row info [srrow release]; nsmutabledictionary *srfield = [[nsmutabledictionary alloc] init]; //an element of sec dimension [srfield setobject:@"read" forkey:@"descr"]; //set rest of objects [srrow addobject:srfield]; //add field sec dimension [srfield release];

now, @ "field" utilize code such following:

[[srdata objectatindex:0] objectatindex:0]; //get first element in first array (the sec dimension)

iphone objective-c ios nsmutablearray

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -