- Objective-C Basics
- Objective-C Home
- Objective-C Program Structure
- Objective-C Basic Syntax
- Objective-C Data Types
- Objective-C Constants
- Objective-C Variables
- Objective-C Operators
- Objective-C Loops
- Objective-C Decision Making
- Objective-C Functions
- Objective-C Numbers
- Objective-C Blocks
- Objective-C Arrays
- Objective-C Strings
- Objective-C Pointers
- Objective-C Structures
- Objective-C Preprocessors
- Objective-C Typedef
- Objective-C Type Casting
- Objective-C Object Oriented
- Objective-C Classes & Objects
- Objective-C Polymorphism
- Objective-C Inheritance
- Objective-C Data Encapsulation
- Objective-C Advance
- Objective-C Category
- Objective-C Extension
- Objective-C Posing
- Objective-C Protocol
- Objective-C Composite Object
- Objective-C Dynamic Binding
- Objective-C Foundation Framework
- Objective-C Fast Enumeration
- Objective-C Log Handling
- Objective-C Error Handling
- Objective-C Command Line Arguments
- Objective-C Memory Management
- Objective-C Test
- Objective-C Online Test
- Give Online Test
- All Test List
Objective-C Fast Enumeration
Fast enumeration is the feature of Objective-C, helps in enumerating through a collection. Collections are the fundamental constructs. It is used to hold and manage the other objects. The main purpose of a collection is, it provides a common way to store and retrieve the object efficiently.
There are different types of collections in Objective-C. The most common collections in Objective-C are:
- NSSet
- NSDictionary
- NSArray
- NSMutableSet
- NSMutableDictionary
- NSMutableArray
Here is the general form to use fast enumeration in Objective-C:
for(classType variable in collectionObject ) { statements }
Objective-C Fast Enumeration Example
Here is an example program, illustrating fast enumeration in Objective-C:
/* Objective-C Fast Enumeration - Example Program */ #import <Foundation/Foundation.h> int main() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSArray *array = [[NSArray alloc] initWithObjects:@"string1", @"string2",@"string3",nil]; for(NSString *aString in array) { NSLog(@"Value = %@",aString); } [pool drain]; return 0; }
When we compile and execute the above program, it will produce the following output:
2014-10-15 06:26:22.835 demo[7426] Value = string1 2014-10-15 06:26:22.836 demo[7426] Value = string2 2014-10-15 06:26:22.836 demo[7426] Value = string3
« Previous Tutorial Next Tutorial »