Changes

Objective-C Enumerators

3 bytes added, 14:32, 20 November 2009
no edit summary
== Why Use Enumerators ==
As previously described, enumerators allow the programmer to predefine the range of values that can be assigned to a variable and use self-explanatory names when setting those values. The benefits of this are twofold. Firstly this makes code easier to read and understand and secondly this, to a certain extent, allows control of the values that can be assigned (though as we will see later in this chapter, enforcement is rather weekweak).
== Declaring an Enumeration ==
<tt>2009-10-21 10:25:46.640 t[11525:10b] Current temperature is 95</tt>
As we can see, although we assigned ''hot'' to our currentTemp variable, Objective-C translated it to the corresponding number 95. If we attempt to assign a value using an undefined name as follows the code will fail to compile with a '''tepid' undeclared'' error message:
<pre>