I am not sure how this is possible but I have a for loop not incrementing properly through an array.
Basically what I have is:
for (AISMessage *report in disarray){
NSLog(@"Position of array = %ld\n", [aisArray indexOfObject:report]);
}
There is more code in the loop but is nothing strange just formatting some of the data in the object and outputting it to a file.
The output of these lines would look something like:
Position of array = 0
…
Posiiton of array = 78176
Posiiton of array = 78177
Posiiton of array = 78178
Posiiton of array = 78178
Posiiton of array = 78180
Posiiton of array = 78181
…
Posiiton of array = 490187
For some reason the report at index 78178 gets read in twice and the report at 78179 gets skipped completely.
Any ideas on what may cause this?
I am totally confused.
Thanks in advance,
Jason
The object occurs twice in the array, so the
indexOfObjectfinds the element at index 78179 at index 78178.In other words, you have this case:
Also, you’re not searching the same array you’re iterating over, that might have something to do with it as well.
Since the positions reported are so high, I would try to find a better data structure than a simple array. For it to report a position of 78178, it will have to have compared the object against the preceeding 78177 elements, and this will only take more and more time as you get further into the array.