Last active
October 21, 2019 10:09
-
-
Save buddax2/1587103c83ea88163ef5c1e1497d44e5 to your computer and use it in GitHub Desktop.
Update or set new date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional where Wrapped == Date { | |
mutating func updateOrSet(newDate: Date?, comparedBy: (Date, Date) -> Bool) { | |
if let currentDate = self, let nDate = newDate { | |
self = comparedBy(currentDate, nDate) ? currentDate : nDate | |
} | |
else { | |
self = newDate | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
resultDate.updateOrSet(newDate: lastDate, comparedBy: <)