Skip to content

Instantly share code, notes, and snippets.

@lfaoro
Created August 29, 2014 18:45
Show Gist options
  • Save lfaoro/9a4b7e5c243fc0802090 to your computer and use it in GitHub Desktop.
Save lfaoro/9a4b7e5c243fc0802090 to your computer and use it in GitHub Desktop.
Challenge
“Challenge
Use two instances of NSDate to figure out how many seconds you have been alive.
First, NSDate has an instance method timeIntervalSinceDate:. This method takes one argument – another instance of NSDate. It returns the number of seconds between the NSDate that received the message and the NSDate that was passed in as the argument.
It looks something like this:
double secondsSinceEarlierDate = [laterDate timeIntervalSinceDate:earlierDate];
Second, you will need to create a new date object that is set to a given year, month, etc. You will do this with the help of an NSDateComponents object and an NSCalendar object. Here is an example:
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:1969];
[comps setMonth:4];
[comps setDay:30];
[comps setHour:13];”
Excerpt From: Ward, Mikey. “Objective-C Programming: The Big Nerd Ranch Guide, 2/e (Big Nerd Ranch Guides).” iBooks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment