ADD This code to your project and comparing dates is easier than ever
Extended NSDate
extension nsdate{func isgreaterthandate (datetocompare:nsdate)-Bool {varIsgreater =false ifSelf.compare (datetocompare) = =nscomparisonresult.ordereddescending {isgreater=true } returnIsgreater} func islessthandate (datetocompare:nsdate)-Bool {varIsless =false ifSelf.compare (datetocompare) = =nscomparisonresult.orderedascending {isless=true } returnIsless} func addDays (daystoadd:int)-NSDate {varSecondsindays:nstimeinterval = Double (daystoadd) * -* -* - varDatewithdaysadded:nsdate =self.datebyaddingtimeinterval (secondsindays)returndatewithdaysadded} func addHours (hourstoadd:int)-NSDate {varSecondsinhours:nstimeinterval = Double (hourstoadd) * -* - varDatewithhoursadded:nsdate =self.datebyaddingtimeinterval (secondsinhours)returndatewithhoursadded}}
It's easy-to-use. Here's a couple of examples
On the. Swift call on the line, easy!
var today = NSDate () var onehourfromnow = today.addhours (1) if Today.isgreaterthandate (onehourfromnow) { println (" Something is terrebly wrong. ")} var aweekfromnow = today.adddays (7)
Original link: http://myxcode.net/2015/08/30/comparing-dates-in-swift/
The "Swift" date comparison function records the comparing date in Swift