Last active
August 26, 2016 06:58
-
-
Save dfelber/e7baa7958a861a870dbd567c0d8253bb to your computer and use it in GitHub Desktop.
Compare NSDate with comparison operators
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
public func <(a: NSDate, b: NSDate) -> Bool { | |
return a.compare(b) == NSComparisonResult.OrderedAscending | |
} | |
public func >(a: NSDate, b: NSDate) -> Bool { | |
return a.compare(b) == NSComparisonResult.OrderedDescending | |
} | |
public func ==(a: NSDate, b: NSDate) -> Bool { | |
return a.compare(b) == NSComparisonResult.OrderedSame | |
} | |
public func >=(a: NSDate, b: NSDate) -> Bool { | |
return a > b || a == b | |
} | |
public func <=(a: NSDate, b: NSDate) -> Bool { | |
return a < b || a == b | |
} | |
extension NSDate: Comparable {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment