From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/gcc~13/using-fast-enumeration.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 devdocs/gcc~13/using-fast-enumeration.html (limited to 'devdocs/gcc~13/using-fast-enumeration.html') diff --git a/devdocs/gcc~13/using-fast-enumeration.html b/devdocs/gcc~13/using-fast-enumeration.html new file mode 100644 index 00000000..f212bd86 --- /dev/null +++ b/devdocs/gcc~13/using-fast-enumeration.html @@ -0,0 +1,18 @@ +

8.9.1 Using Fast Enumeration

GNU Objective-C provides support for the fast enumeration syntax:

id array = …;
+id object;
+
+for (object in array)
+{
+  /* Do something with 'object' */
+}
+

array needs to be an Objective-C object (usually a collection object, for example an array, a dictionary or a set) which implements the “Fast Enumeration Protocol” (see below). If you are using a Foundation library such as GNUstep Base or Apple Cocoa Foundation, all collection objects in the library implement this protocol and can be used in this way.

The code above would iterate over all objects in array. For each of them, it assigns it to object, then executes the Do something with 'object' statements.

Here is a fully worked-out example using a Foundation library (which provides the implementation of NSArray, NSString and NSLog):

NSArray *array = [NSArray arrayWithObjects: @"1", @"2", @"3", nil];
+NSString *object;
+
+for (object in array)
+  NSLog (@"Iterating over %@", object);
+
+

+ © Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
+ https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Using-fast-enumeration.html +

+
-- cgit v1.2.3