Add days to my existing date iOS swift

 Problem:

I had one date with me.I want to add some days to the date and get the new date.

Solution:

extension Date {

    func addDays(daysAdd: Int) -> Date {

        let secondsInDays: TimeInterval = Double(daysToAdd) * 60 * 60 * 24

        let dateWithDaysAdded: Date = self.addingTimeInterval(secondsInDays)

        //Return Result

        return dateWithDaysAdded

    }

}



Call the above function as like below.


let newDate = yourdate.addDays(1)



newDate will store the new date after appending one day.

Comments

Popular posts from this blog

store cgpoint in userdefaults iOS swift

libc++abi: terminating due to uncaught exception of type NSException iOS swift