I've allocated a mutable array as:
self.allisonHall.hours = [[NSMutableArray alloc] initWithCapacity:7];
and filled it with data:
self.allisonHall.hours = @[
@[
@[@600,@780],
@[@1005,@1170]
],
@[
@[@450,@585],
@[@705,@795],
@[@1005,@1140]
],
@[
@[@450,@585],
@[@705,@795],
@[@1005,@1140]
],
@[
@[@450,@585],
@[@705,@795],
@[@1005,@1140]
],
@[
@[@450,@585],
@[@705,@795],
@[@1005,@1140]
],
@[
@[@450,@585],
@[@705,@795],
@[@1005,@1140]
],
@[
@[@645,@810],
@[@1005,@1170]
],
];
When I attempt to access an element using the code int open = _hours[0][i][0];
or
int open = _hours[0][i][1];
where i is 2 or 3 (depending on the number of objects in each of the 7 parent arrays, open is assigned as 146980960, clearly a memory address. When debugging, the command
po open
results in 600, 450, etc.—all correct values of the array. However, when I'm performing inequalities later in the function, they do not resolve as expected because open is 146980960 within the scope.
Why does "po" print the variable as expected while it does not exist this way in the function? And how can I resolve it?
Thanks
[[NSArray alloc] init]then fill it with data will the same problem occur? Or is it necessary to initialize the array with the data?@[…]creates an array. Just assign that directly to yourNSArray *variable; don't assign something else (an empty array or otherwise) to that variable just to overwrite it a moment later.