December 2013
Beginner
576 pages
16h 4m
English
Chapter 4, “Data Types and Expressions,” briefly touched on the id data type and noted that it is a generic object type. That is, id can be used for storing objects that belong to any class. The real power of this data type is exploited when it’s used this way to store different types of objects in a variable during the execution of a program. Study Program 9.2 and its associated output.
Program 9.2 Test Program main.m
// Illustrate Dynamic Typing and Binding#import "Fraction.h"#import "Complex.h"int main (int argc, char * argv[]){ @autoreleasepool { id dataValue; Fraction *f1 = [[Fraction alloc] init]; Complex *c1 = [[Complex alloc] init]; [f1 setTo: 2 ...
Read now
Unlock full access