Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If an id data type can be used to store any object, why don’t you just declare all your objects as type id? For several reasons, you don’t want to get into the habit of overusing this generic class data type.
First, when you define a variable to be an object from a particular class, you are using what’s known as static typing. The word static refers to the fact that the variable is always used to store objects from the particular class. So the class of the object stored in that type is predeterminate, or static. When you use static typing, the compiler ensures, to the best of its ability, that the variable is used consistently throughout the program. The compiler can check to ensure that a method applied to an object is defined or inherited by that class; if not, it issues a warning message. Thus, when you declare a Rectangle variable called myRect in your program, the compiler checks that any methods you invoke on myRect are defined in the Rectangle class or are inherited from its superclass.