timeIntervalSince1970 error

The book said two “Create a new Command Line Tool project named TimeAfterTime. Make its type Foundation” The type “Foundation” did not show uo in my version of Xcode (version 7.2), so I choose “Objective C”. It did have the same “#import <Foundation/Foundation.h>” so I assume it was OK to use “Objective C” as the type.

However, when I insert this line of code: “double seconds = [now timeIntervalSince1970];” I get an error that timeIntervalSince1970 is an undeclared identifier. Has timeIntervalSince1970 been dropped or am I doing something wrong?

Thanks for your help…
Earl Staley

You are correct that “Objective-C” was the correct project type, in lieu of “Foundation”.

NSDate’s -timeIntervalSince1970 method is still available. By any chance, might you post your code so that we can see it in context?

Thank you for your reply.

Here is my code:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here…
NSDate *now = [NSDate date];
NSLog(@“This NSDate object lives at address %p”,now);
NSLog(@“The date is %@”,now);
double seconds=[now,timeIntervalSince1970];
return 0;

The “timeIntervalSince1970” line has a red exclamation point next to it with the message “Use of an undeclared identifier ‘timeIntervalSince1970’”.

BTW, seeing this forum and how it was laid out was a big part of my decision to buy your book. The book is an excellent resource.

Earl Staley

I found the error.

double seconds=[now,timeIntervalSince1970];

should be

double seconds=[now timeIntervalSince1970];

(i.e. no comma)

Thank You…
Earl Staley

What is the meaning of the numbers (18:44:46 +0000) after the date?

The date is 2016-01-02 18:44:46 +0000

Earl Staley

Good eye! Nailed it.

Also, glad you’re liking the book!

An NSDate instance refers not just to a date, but a date and time. Most specifically, a singular moment in time. So the bit after the date is the time (using 24h notation) and the timezone offset of the preceding info; +0000 means GMT.