【发布时间】:2015-10-22 10:17:12
【问题描述】:
要从 NSDateComponents 对象中获取分钟值,请执行以下操作:
var someNSDateComponentsObject: NSDateComponents = NSCalendar.currentCalendar().components(timeUnit, fromDate: someDate, toDate: someOtherDate, options: nil)
someNSDateComponentsObject.minute
如果我不想使用someNSDateComponentsObject.minute,而是想使用timeUnit 的值,即NSCalendarUnit,该怎么办? switch 语句会是唯一的选择,还是有更优雅的解决方案?
总的来说,我想要完成的事情是在两个日期之间获取timeUnits 的数量。有没有更好的方法来避免这个问题?
【问题讨论】:
标签: ios swift cocoa-touch nsdatecomponents