-2
        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

I am getting this error in Swift 4. How to resolve this.

enter image description here

Prasad A
  • 77
  • 7
  • https://stackoverflow.com/questions/39443953/swift-3-error-argument-labels-do-not-match-any-available-overloads – Night Programmer Apr 05 '18 at 05:52
  • Where is the remaining code.? At least show what is the argument value? – Mani Apr 05 '18 at 05:57
  • Check [this](https://developer.apple.com/documentation/foundation/nscalendar/1407925-components). Better consider adopting `Calendar` than `NSCalendar` in Swift. – OOPer Apr 05 '18 at 06:07
  • 2
    Don't use `NSCalendar` in Swift. Use `Calendar`. – rmaddy Apr 05 '18 at 06:24
  • I have used Calender still it is not working. – Prasad A Apr 05 '18 at 06:38
  • Use `Calendar`. Avoid `NSStuff` when possible and use `Stuff` if available. Comment that line, and then rewrite it char by char letting XCode completion help you to find the equivalent and the correct syntax. – Larme Apr 05 '18 at 06:50
  • The signature of the method is wrong. It's always worth it to read the [documentation](https://developer.apple.com/documentation/foundation/calendar) – vadian Apr 05 '18 at 06:55

1 Answers1

0

Since Swift 3, the Objective-C method components:fromDate:toDate:options: is imported as components(_:from:to:options:) in Swift.

But rewriting your code following the signature above, I get this error:

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:)'

Use Calendar instead of NSCalendar and 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)
OOPer
  • 47,149
  • 6
  • 107
  • 142