Changes

Jump to: navigation, search

Objective-C 2.0 Data Types

16 bytes added, 19:43, 17 November 2009
no edit summary
== int Data Type ==
The Objective-C ''int'' data type can store a positive or negative whole number (in other words a number with no decimal places). The actual size, or range of integer that can be handled by the ''int'' data type is machine and compiler implementation dependent. Typically the amount of storage allocated to int values is either 32-bit or 64-bit depending on the implementation of Objective-C on that platform or the CPU on which the compiler is running. It is important to note, however, that the operating system also plays a role in whether int values are 32 or 64-bit. For example the CPU in a computer may be 64-bit but the operating system running on it may only be 32-bit.
For example, on a 32-bit implementation, the maximum range of an unsigned ''int'' is 0 to 4294967295. On a 64-bit system this range would be 0 to 18,446,744,073,709,551,615. When dealing with ''signed int'' values, the ranges are −2,147,483,648 to +2,147,483,647 and −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 for 32-bit and 64-bit implementations respectively.
=== Special Characters/Escape Sequences ===
In addition to the standard set of characters outlined above, there is also a range of ''special characters'' (also referred to as ''escape sequences'') available for specifying items such as a new line or tab. These special characters are identified by prefixing the character with a backslash (a concept referred to as ''escaping''). For example, the following assigns a new line to the variable named newline:
<pre>
== id Data Type ==
As we will see in later chapters of this book, Objective-C is an object oriented language. As such much of the way a program will be structured is in the form of reusable objects. These objects are called upon to perform tasks and return results. Often, the information passed into an object and the results returned will be in the form of yet another object. The ''id'' data type is a general purpose data type that can be used to store a reference to any object, regardless of its type.
== BOOL Data Type ==
Objective-C, like other languages, includes a data type for the purpose of handling true or false (1 or 0) conditions. Such a data type is declared using either the ''_Bool'' or ''BOOL'' keywords. Both of the following expression expressions are valid:
<tt>_Bool flag = 0;</tt><br>
=== signed / unsigned ===
By default, an integer is assumed to be signed. In other words the compiler assumes that an integer variable will be called upon to store either an a negative or positive number. This limits the extent that the range can reach in either direction. For example, a 32-bit ''int'' has a range of 4,294,967,295. In practice, because the value could be positive or negative the range is actually −2,147,483,648 to +2,147,483,647. If we know that a variable will never be called upon to store a negative value, we can declare it as unsigned, thereby extending the (positive) range to 0 to +4,294,967,295. An unsigned int is specified as follows:
<pre>

Navigation menu