Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

12. Objects > Message anatomy

Message anatomy

A message send is always surrounded by square brackets, and it always has at least two parts:

  • a pointer to the object that is receiving the message

  • the name of the method to be triggered

A message send (like a function call) can also have arguments. Let’s look at an example.

NSDate objects represent a particular date and time. An instance of NSDate can tell you the difference (in seconds) between the date/time it represents and 12:00AM (GMT) on Jan 1, 1970. Ask yours this question by sending the message timeIntervalSince1970 to the NSDate object pointed to by now.

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    @autoreleasepool {

        NSDate *now = [NSDate date];
        NSLog(@"The date is %@", now);
        double seconds = [now timeIntervalSince1970];
        NSLog(@"It has been %f seconds since the start of 1970.", seconds);

    }
    return 0;
}

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial