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; }
Now say you want a new date object – one that is 100,000 seconds later from the one you already have.
The NSDate class has a method called dateByAddingTimeInterval:. You can send this message to the original date object to get the new date object. This method takes an argument: the number of seconds to add. Use it to create a new date object in your main() function:
#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); NSDate *later = [now dateByAddingTimeInterval:100000]; NSLog(@"In 100,000 seconds it will be %@", later); } return 0; }
In the message send [now dateByAddingTimeInterval:100000],