Hi I get this error in swift 2.0
Cannot invoke 'components' with an argument list of type '(NSCalendarUnit, fromDate: NSDate?, toDate: NSDate?, options: nil)'
var hoy = dataFormatter.stringFromDate(NSDate())
var despues = dataFormatter.stringFromDate(fecha)
var calHoy = dataFormatter.dateFromString(hoy)
var calcDesp = dataFormatter.dateFromString(despues)
let cal = NSCalendar.currentCalendar()
let unit:NSCalendarUnit = .Day
let components = cal.components(unit, fromDate: calcDesp, toDate: calHoy, options: nil)
As of Swift 2,
NS_OPTIONS
(such asNSCalendarOptions
) are mapped to Swift as aOptionSetType
which offers a set-like interface. In particular, "no options" can now be specified as[]
instead ofnil
:See also Swift 2.0 - Binary Operator "|" cannot be applied to two UIUserNotificationType operands and the recently added answers to How to create NS_OPTIONS-style bitmask enumerations in Swift? for more information.