Change needed components to day, hour or minute, which difference you want.
If NSDayCalendarUnit is selected then it'll return the number of days between two dates similarly for NSHourCalendarUnit and NSMinuteCalendarUnit
Swift 4 version
let cal = Calendar.current
let d1 = Date()
let d2 = Date.init(timeIntervalSince1970: 1524787200) // April 27, 2018 12:00:00 AM
let components = cal.dateComponents([.hour], from: d2, to: d1)
let diff = components.hour!
Checkout : It takes care of daylight saving, leap year as it used iOS calendar to calculate. You can change the string and conditions to includes minutes with hours and days.