Why can I not access the 4th element of an NSMutableArray when I initialise with a NSString object rather than input the text manually?
For Example:
NSString * d = @"d";
self.arr = [[NSMutableArray alloc] initWithObjects:
[NSMutableArray arrayWithObjects:@"A",@"B",@"C",d,nil],
[NSMutableArray arrayWithObjects:@"A",@"B",@"C",@"d",nil],
nil];
This causes a beyond bounds error (NSString):
NSMutableArray *subArray = [self.arr objectAtIndex:0];
question = [subArray objectAtIndex:3];
This doesn't (@"d"):
NSMutableArray *subArray = [self.arr objectAtIndex:1];
question = [subArray objectAtIndex:3];
Why does this happen? Surely they are the same thing? I was hoping to reduce the amount of times I would have to write @"d".
NSLog(@"%@",[[self.arr firstObject ]objectAtIndex:3]);NSLog(@"%@", self.arr)). It's possible thatdisn't really set to what you think it is, and it's in fact nil at the time of array creation.