Declared in NGLIterator.h

Overview

The NGLIterator protocol defines the basic methods to use the Iterator Pattern (Design Pattern).

Unlike NSFastEnumeration, this protocol works with any kind of data type, including the basic C data types. To use the iterator you can use it within a while loop.

The advantage of the iterator is that it can handle changes inside the collection during the loop without break the integrity.

Tasks

Instance Methods

nextIterator

Iterator loop throughout this library’s instances.

- (void *)nextIterator

Return Value

A pointer or NULL when reaches the end.

Discussion

Iterator loop throughout this library’s instances.

This method returns a pointer to each object/instance inside this library. It uses the iterator pattern to create an ordered loop from the first element to the last one. To use this method call it inside a while loop:


id variable;

while ((variable = [myClassWithIterator nextIterator]))
{
    // Do something...
}

The iterator will be automatically reseted every time it reaches the end of this library. But if you need to reset the iterator before it reaches the end of this library, use the resetIterator method.

Declared In

NGLIterator.h

resetIterator

Forces the iterator pattern return to 0.

- (void)resetIterator

Discussion

Forces the iterator pattern return to 0.

Using the nextIterator method, the iterator pattern will be returned to 0 automatically, but if you need to reset the iterator pattern before the last loop you can call this method.

See Also

Declared In

NGLIterator.h