gcc: Using fast enumeration
1
1 8.9.1 Using Fast Enumeration
1 ----------------------------
1
1 GNU Objective-C provides support for the fast enumeration syntax:
1
1 id array = ...;
1 id object;
1
1 for (object in array)
1 {
1 /* Do something with 'object' */
1 }
1
1 'array' needs to be an Objective-C object (usually a collection object,
1 for example an array, a dictionary or a set) which implements the "Fast
1 Enumeration Protocol" (see below). If you are using a Foundation
1 library such as GNUstep Base or Apple Cocoa Foundation, all collection
1 objects in the library implement this protocol and can be used in this
1 way.
1
1 The code above would iterate over all objects in 'array'. For each of
1 them, it assigns it to 'object', then executes the 'Do something with
1 'object'' statements.
1
1 Here is a fully worked-out example using a Foundation library (which
1 provides the implementation of 'NSArray', 'NSString' and 'NSLog'):
1
1 NSArray *array = [NSArray arrayWithObjects: @"1", @"2", @"3", nil];
1 NSString *object;
1
1 for (object in array)
1 NSLog (@"Iterating over %@", object);
1