Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define 2x2 array in ios?

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[][]

like image 547
mamrezo Avatar asked Apr 24 '26 10:04

mamrezo


2 Answers

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];
like image 55
JeremyP Avatar answered Apr 27 '26 00:04

JeremyP


How to declare a two dimensional array of string type in Objective-C? might give you an idea

like image 45
visakh7 Avatar answered Apr 26 '26 22:04

visakh7