Friday, May 6, 2011

NSArray iteration using NSEnumerator

Following code fragment shows how to iterator elements of an NSArray object using NSEnumerator object. The NSEnumerator object is simply used to display the content of the NSArray object.




NSEnumerator * enumerator = [myArray objectEnumerator];
id element;

while(element = [enumerator nextObject])
    {
    // Do your thing with the object.
    NSLog(element);
    }