For the answer to exercise 3, I’m not too sure what can be the right answer for the simple (not fast) iterator. I think that if we can cache in the NSEnumerator’s object the scanned object value, then we should be able, when calling the nextObject method, to ask the array at which index is the scanned object(with indexOfObjectIdenticalTo:) and from there to pick up the next one.
This solutions has a few problems however:
[li]If you have more than one time the same object in the array you will trigger infinite loop.[/li]
[li]If at each iteration step you add object after the actual position you also trigger infinite loop.[/li]
[li]You can skip some object if you a twice the same object in the array and you remove the first one during the enumration.[/li]
[li]You have problem when your code is multithreaded (thread A remove the actual object before thread B is able to find its position).[/li]
[li]Possibly some other cases I cannot think about[/li][/ul]
Has someone other ideas to answer the question (with less problems)? What do you think about my version?