how to define 2x2 or 3X.. array in ios? like this
[name=john , age=21 , num=1]
[name=max , age=25 , num=2]
[name=petter , age=22 , num=3]
with columns in NSMutableArray you can only add rows with objects; i want this array[][]
Looking at your example, I wouldn't do it with arrays, or not just arrays. I'd have an array of dictionaries or an array of custom objects with the properties name, age and num. With dictionaries:
NSArray* theArray = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@"john", @"name",
[NSNumber numberWithInt: 21], @"age",
[NSNumber numberWithInt: 1], @"num",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"max", @"name",
[NSNumber numberWithInt: 25], @"age",
[NSNumber numberWithInt: 2], @"num",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"petter", @"name",
[NSNumber numberWithInt: 22], @"age",
[NSNumber numberWithInt: 3], @"num",
nil],
nil];
How to declare a two dimensional array of string type in Objective-C? might give you an idea
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With