0

I'm converting some working Objective-c code to Swift. It's all ported but I'm getting an error on this line:

var components = calendar.components(NSCalendarUnit.MinuteCalendarUnit, fromDate: start, toDate: end, options: 0)

It tells me toDate is an extra argument but the method was generated by code completion so I'm sure it's correct.

1 Answers1

0

Such a message often is really confusing. It often means, that one of your parameter's value has a different type then it should have.

Here, your value "0" as options-parameter isn't valid. This parameter wants an NSCalendarOptions.allZeros(in your case), another NSCalendarOptions-value, or nil:

var components = calendar.components(NSCalendarUnit.MinuteCalendarUnit, fromDate: start, toDate: end, options: NSCalendarOptions.allZeros)

var components = calendar.components(NSCalendarUnit.MinuteCalendarUnit, fromDate: start, toDate: end, options: nil)
Christian
  • 22,585
  • 9
  • 80
  • 106