I’m trying to use a 1D array like a 2D this way but I can’t figure it out.
Given an array like this:
NSArray *myArray = @[@0,@1,@2,@3,@4,@5];
Is it possible to acces ‘4’ using an NSIndexPath defined like this?:
NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:1];
More generally, you can use an index path of dimension A to walk an array of dimension B. You can also make a rule that says what to do when you have extra dimensions in either your path or in your array.
That rule can look something like this: if I run out of path dimensions, return whatever object I find at the end of the path. If I run out of array dimensions (like the case in your question) discard the remainder of the path and return whatever non-array I found.
In code:
Call it like this…
This produces the output “there”, for the given index path.