Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whither NSDate dateByAddingTimeInterval on iPhone OS?

Greetings! I must be seeing things. Look at this excerpt from the iPhone OS reference library:

addTimeInterval: Returns a new NSDate object that is set to a given number of seconds relative to the receiver. (Deprecated. This method has been replaced by dateByAddingTimeInterval:.)

However, it is nowhere to be found in the docs, nor in the headers. If I look at the Mac OS SDK, then I find it.

Typo? Just keep using addTimeInterval: after all??

like image 736
Joe D'Andrea Avatar asked Oct 27 '09 19:10

Joe D'Andrea


People also ask

What is NSDate?

The NSDate class provides methods for comparing dates, calculating the time interval between two dates, and creating a new date from a time interval relative to another date.

How do I increment a Date in Swift?

Adding Datelet monthsToAdd = 2 let daysToAdd = 1 let yearsToAdd = 1 let currentDate = Date() var dateComponent = DateComponents() dateComponent. month = monthsToAdd dateComponent.

What is timeIntervalSince1970?

timeIntervalSince1970 is the number of seconds since January, 1st, 1970, 12:00 am (mid night) timeIntervalSinceNow is the number of seconds since now.

What is NSTimeInterval?

TimeInterval (née NSTimeInterval ) is a typealias for Double that represents duration as a number of seconds. You'll see it as a parameter or return type for APIs that deal with a duration of time.


2 Answers

It's actually an error in the docs. addTimeInterval: is deprecated in Mac OS X 10.6 but not in iPhone OS 3.1.2.

You can look at the NSDate.h in MacOS and in iPhoneOS and you'll see the difference.

NSDate.h in iPhone OS

- (id)addTimeInterval:(NSTimeInterval)seconds;

and NSDate.h in Mac OS 10.6

- (id)addTimeInterval:(NSTimeInterval)seconds DEPRECATED_IN_MAC_OS_X_VERSION_10_6_AND_LATER;
- (id)dateByAddingTimeInterval:(NSTimeInterval)ti AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
like image 84
gcamp Avatar answered Sep 22 '22 23:09

gcamp


Looks like a typo to me as I see the same thing on my system as you do. Perhaps they intended to deprecate the method as described but cut it at the last minute, with the incorrect text still in place.

like image 25
Shaggy Frog Avatar answered Sep 25 '22 23:09

Shaggy Frog