import Foundation

extension Date {
    func relative(to date: Date) -> String {
        let interval = timeIntervalSince(date) * -1
        switch interval {
        case let x where x < 1:
            return "now"
        case 1..<60:
            return "just now"
        case 60..<3600:
            return "\(Int(round(interval / 60))) minutes ago"
        case 3600..<86400:
            return "\(Int(round(interval / 3600))) hours ago"
        default:
            return "\(Int(round(interval / 86400))) days ago"
        }
    }
}

import Foundation

extension Date {
    func relative(to date: Date) -> String {
        let interval = timeIntervalSince(date) * -1
        if interval < 1 {
            return "now"
        } else if interval < 60 {
            return "just now"
        } else if interval < 3600 {
            let diff = Int(round(interval / 60))
            return "\(diff) minutes ago"
        } else if interval < 86400 {
            let diff = Int(round(interval / 3600))
            return "\(diff) hours ago"
        }
        let diff = Int(round(interval / 86400))
        return "\(diff) days ago"
    }
}

--- 
+++ 
@@ -3,18 +3,17 @@
 extension Date {
     func relative(to date: Date) -> String {
         let interval = timeIntervalSince(date) * -1
-        if interval < 1 {
+        switch interval {
+        case let x where x < 1:
             return "now"
-        } else if interval < 60 {
+        case 1..<60:
             return "just now"
-        } else if interval < 3600 {
-            let diff = Int(round(interval / 60))
-            return "\(diff) minutes ago"
-        } else if interval < 86400 {
-            let diff = Int(round(interval / 3600))
-            return "\(diff) hours ago"
+        case 60..<3600:
+            return "\(Int(round(interval / 60))) minutes ago"
+        case 3600..<86400:
+            return "\(Int(round(interval / 3600))) hours ago"
+        default:
+            return "\(Int(round(interval / 86400))) days ago"
         }
-        let diff = Int(round(interval / 86400))
-        return "\(diff) days ago"
     }
 }
Use switch case instead of if else
