public func adding(_ component: Calendar.Component, value: Int) -> Date { return Calendar.current.date(byAdding: component, value: value, to: self)! } или так public mutating func add(_ component: Calendar.Component, value: Int) { if let date = Calendar.current.date(byAdding: component, value: value, to: self) { self = date } }
var date = Date() // "Jan 12, 2017, 7:07 PM" date.add(.minute, value: -10) // "Jan 12, 2017, 6:57 PM"
Обсуждают сегодня