Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone iOS 4 addTimeInterval deprecated

I'm using addTimeInterval for creating local notification but it seems that it is now deprecated (iOS 4).

My code:

localNotif.fireDate = [now addTimeInterval:timeInterval]; 

Xcode's warning:

'addTimeInterval:' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:27) 

What should I use instead? Thanks.

like image 860
Iñigo Beitia Avatar asked Jun 16 '10 15:06

Iñigo Beitia


1 Answers

The method has been renamed to -dateByAddingTimeInterval:.

localNotif.fireDate = [now dateByAddingTimeInterval:timeInterval]; 

In Swift 2.2:

localNotif.fireDate = now.dateByAddingTimeInterval(timeInterval) 

In Swift 3:

localNotif.fireDate = now.addingTimeInterval(timeInterval) // or simply localNotif.fireDate = now + timeInterval 
like image 77
kennytm Avatar answered Sep 21 '22 21:09

kennytm