var toTimePVC: UIDatePicker!
var fromPVC: UIDatePicker!
let unit:NSCalendar.Unit = .minute
let cal = NSCalendar.current
let minutesComponents = cal.components(unit, fromDate:fromPVC.date, toDate: toTimePVC.date, options: NSCalendar.Options.MatchStrictly)
let startingTime = cal.components(unit, fromDate: date, toDate: fromPVC.date, options: NSCalendar.Options.MatchStrictly
我在Swift 4中收到此错误。如何解决此问题。
答案 0 :(得分:0)
自Swift 3以来,Objective-C方法components:fromDate:toDate:options:
在Swift中导入为components(_:from:to:options:)
。
但是按照上面的签名重写你的代码,我收到了这个错误:
let minutesComponents = cal.components(unit, from: fromPVC.date, to: toTimePVC.date, options: NSCalendar.Options.matchStrictly)
'components(_:from:to:options:)' has been renamed to 'dateComponents(_:from:to:)'
使用Calendar
代替NSCalendar
和Calendar.dateComponents(_:from:to:)
:
let components: Set<Calendar.Component> = [.minute]
let cal = Calendar.current
let minutesComponents = cal.dateComponents(components, from: fromPVC.date, to: toTimePVC.date)