Advertisements
NSEnumerator by example
Getting the Enumerated Objects
- allObjects
Returns an array of objects the receiver has yet to enumerate.
Example
NSDictionary *eezyDict = @{@"Key1": @"Eezy", @"Key2": @"Tutorials", @"Key3": @"Website"}; NSEnumerator *enumerator = [eezyDict keyEnumerator]; NSLog(@"%@",[enumerator allObjects]);
Output
2014-04-12 05:24:23.625 iOS-Tutorial[1480:a0b] ( Key2, Key1, Key3 )
- nextObject
Returns the next object from the collection being enumerated.
Example
NSDictionary *eezyDict = @{@"Key1": @"Eezy", @"Key2": @"Tutorials", @"Key3": @"Website"}; NSString *key; NSEnumerator *enumerator = [eezyDict keyEnumerator]; while (key = [enumerator nextObject]) { NSLog(@"%@: %@",key, eezyDict[key]); }
Output
2014-04-12 05:27:22.727 iOS-Tutorial[1521:a0b] Key2: Tutorials 2014-04-12 05:27:22.728 iOS-Tutorial[1521:a0b] Key1: Eezy 2014-04-12 05:27:22.729 iOS-Tutorial[1521:a0b] Key3: Website
Advertisements