Objective-C why doesn't my array of array works?
Posted
by Quetsche
on Stack Overflow
See other posts from Stack Overflow
or by Quetsche
Published on 2010-05-04T08:13:11Z
Indexed on
2010/05/04
8:18 UTC
Read the original article
Hit count: 172
This is probably a completely stupid question, but i'm pretty new at objective-C and programing in general. i'm trying to make an array of arrays but can't manage to make it work :
@interface ArraysAndDicts : NSObject {
NSMutableArray * mySimpleArray;
NSMutableArray * myComplicatedArray;
}
the implementation :
-(void)generateValueForArrayOfArrays {
[self generateValueForArray];
//this generates an array with 5 elements 'mySimpleArray'
[myComplicatedArray addObject:mySimpleArray];
NSMutableArray * mySecondaryArray = [[NSMutableArray alloc] init];
[mySecondaryArray addObject:@"twoone"];
[mySecondaryArray addObject:@"twotwo"];
[myComplicatedArray addObject:mySecondaryArray];
(i edited out all the NSLogs for clarity)
When running my app, the console tells me :
mySecondaryArray count = 2
mySimpleArray count = 5
myComplicatedArraycount = 0
So, i know there are other ways to make multidimensional arrays, but i'd really like to know why this doesn't work. Thank you.
© Stack Overflow or respective owner