November 2013
Beginner
325 pages
9h 47m
English
Message sends can be nested. For instance, to find out the number of seconds since the start of 1970, you could write your code this way:
NSDate *now = [NSDate date];
double seconds = [now timeIntervalSince1970];
NSLog(@"It has been %f seconds since the start of 1970", seconds);
Or you could nest the two message sends like this:
double seconds = [[NSDate date] timeIntervalSince1970];
NSLog(@"It has been %f seconds since the start of 1970", seconds);
When message sends are nested, the system will handle the message send on the inside first and then the message that contains it. So date is sent to the NSDate class, and the result of that (a pointer to the newly-created instance) is sent timeIntervalSince1970 ...
Read now
Unlock full access