timeIntervalSince1970 return type


#1

In the methods and messages section, there is a comment that the NSDate timeIntervalSince1970 method returns a double. However, when I look up the method in NSDate documentation, it shows first that the return type is NSTimeInterval which led to some confusion. I later find that NSTimeInterval is simply a double. Why would this timeIntervalSince1970 method not explicitly return double (rather than hiding it behind NSTimeInterval)?


#2

Hiding it behind NSTimeInterval affords invaluable benefits.

Imagine that all time intervals, say thousands of them, were coded as double type, and one day it became necessary to change them to a new type, cool_double type. Then, you would have to make thousands of modifications to accommodate the new type.

But by hiding the double behind NSTimeInterval, you would modify only one line of code.

[Accelerate your learning and become a competent programmer: pretty-function.org]


#3

Thanks for the explanation. So in that case, would it have been proper to change the following line in the tutorial

double seconds = [now timeIntervalSince1970];

to

NSTimeInterval seconds = [now timeIntervalSince1970];

This way, if NSTimeInterval changes, your code will still function. Am I interpreting this correctly?


#4

Yes.