I declared a NSArray object in .h file as
@property (nonatomic, assign) NSArray *scnArray;
and in .h file under - (void)viewDidLoad I created three different NSArray objects as
NSArray *obj1 = [[NSArray alloc] initWithObjects:@"1",@"0",@"0",nil];
NSArray *obj2 = [[NSArray alloc] initWithObjects:@"0",@"3",@"0",nil];
NSArray *obj3 = [[NSArray alloc] initWithObjects:@"0",@"0",@"5",nil];
scnArray = [[NSArray alloc] initWithArray:obj1];
[scnArray arrayByAddingObjectsFromArray:obj2];
[scnArray arrayByAddingObjectsFromArray:obj3];
and if I access this scnArray from any other function
NSArray *caseArray = [scnArray objectAtIndex:index];//index will be 0, 1, 2…
I am getting BAD_ACCESS_ERROR. What is the problem here and how can I correct to use it?
Try this :
The
arrayByAddingObjectsFromArray:function adds all objects from array B to array A, and return the result (=the array containing both A’s and B’s elements).So, you should simply GET that result… 🙂
IMPORTANT :
scnArrayMUST be anNSMutableArrayarray, and NOT anNSArray(it’s changing, right?); so make sure you edit that part too…ALSO :
NSArray *caseArray = [scnArray objectAtIndex:index];– this doesn’t make any sense. Setting an array to an ELEMENT of thescnArray? It doesn’t contain arrays, right? It just contains ELEMENTS of those arrays (the ones we’ve added)…