Calculating the difference between two dates in Swift

I ended up creating a custom operator for Date: extension Date { static func – (lhs: Date, rhs: Date) -> TimeInterval { return lhs.timeIntervalSinceReferenceDate – rhs.timeIntervalSinceReferenceDate } } With this operator I can now compute the difference between two dates on a more abstract level without caring about timeIntervalSinceReferenceDate or what exactly the reference date …

Read more