Working with dates in Swift doesn’t have to be hard!
Create an extension to Date
:
extension Date {
var dayAfter: Date {
return Calendar.current.date(byAdding: .day, value: 1, to: self)!
}
var dayBefore: Date {
return Calendar.current.date(byAdding: .day, value: -1, to: self)!
}
}
Now you can access these variables like so:
let tomorrow = Date().dayAfter
let yesterday = Date().dayBefore
The Complete iOS App Development Bootcamp
Disclosure: This website may contain affiliate links, meaning when you click the links and make a purchase, we receive a commission.