Traversing two-dimensional array, using for-in syntax
-
19-06-2021 - |
Question
I'm traversing through a two-dimensional array like this:
for (menuViewController *aSelection in mainDataArray) {
...
}
However, how do I access the lower arrays' data? This following code doesn't work, but gives you the idea of what I mean:
for (menuViewController *aSelection in mainDataArray) {
NSLog(@"Data: %@", [aSelection objectAtIndex:2]);
}
Solution
If you are traversing an array within an array, can you try the following?
for (NSArray* aSelection in mainDataArray) {
NSLog(@"Data: %@", [aSelection objectAtIndex:2]);
}
OTHER TIPS
Why don't you do a second for-in statement
for (NSArray* aSelection in mainDataArray) {
for (NSArray* bSelection in aSelection) {
//Do something innovative :)
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow