Changes

Jump to: navigation, search

Objective-C Enumerators

9 bytes added, 14:56, 21 October 2009
Declaring an Enumeration
The syntax for declaring an enumeration is as follows:
 enum ''<name>'' ( { ''<value name 1>'', ''<value name 2>'', ... )}
In the above syntax outline, ''enum'' is the keyword that tells the compiler we are creating an enumeration, ''<name>'' is the name to be assigned to the enumeration and the ''<value name>'' fields are the names that can be used to set the variable. Internally, enumerators use numbers corresponding to the value names. By default the first value corresponds to 0, the second to 1 and so on. It is also possible to specify the values used by each value name:
enum ''<name>'' ( { ''<value name 1>'' = ''<value1>'', ''<value name 2>'' = ''<value2>'', ... )};
For example, we can specify an enumeration for the days of the week:
</pre>
In the above construct, monday is equal to 0, tuesday is 1 and so on. If we specify a number for just one entry, the remainder remaining values will follow on form from that number. For example:
<pre>

Navigation menu