Date calculations in SWIFT

I am just starting to learn swift and i am finding it really frustrating updating my old app.


How do I get a date from a UI Datepicker and calculate a future date , seemed really easy in Obj C but with NSDate, NSCalendar and date components in swift it seems a nightmare??


Ive been scouring internet and YouTube for info but nothing other than displaying datepicker date in a label.



I want user to select a date on the datepicker then use this date to calculate a future date and possibly create a calendar reminder.




Any help on this would be a life saver!!!


G

Hi.... ironmonkeyvet


It is very easy to get future date by adding components to selected date.



let today = NSDate() //Use datePicker.date
        let tomorrow = NSCalendar.current.date(byAdding: Calendar.Component.day, //Here you can add year, month, hour, etc.
                                              value: 1,  //Here you can add number of units
                                              to: today as Date)



But please note that it is in Xcode 8.0 and swift 3


In swift 2.x, it may be like :



let today = NSDate() 
let tomorrow = NSCalendar.currentCalendar().dateByAddingUnit(.Day, 
                                                             value:1,
                                                             toDate:today,
                                                             options:[])
Date calculations in SWIFT
 
 
Q