I am trying to write the following Objective-C code in swift:
NSCalendar *cal = [NSCalendar currentCalendar]; NSDate *now = [NSDate date]; NSDate *startOfTheWeek; NSTimeInterval interval; [cal rangeOfUnit:NSWeekCalendarUnit startDate:&startOfTheWeek interval:&interval forDate:now];
he will write the start of this week on startOfTheWeek and the duration of the weeks before interval .
I am writing on the playground
let now:NSDate = NSDate() var startDate:NSDate var duration: NSTimeInterval
Although code completion tells me that signature
cal.rangeOfUnit(<#unit: NSCalendarUnit#>, startDate: AutoreleasingUnsafePointer<NSDate?>, interval: <#CMutablePointer<NSTimeInterval>#>, forDate: <#NSDate?#>)
an error occurs saying Extra argument 'interval' in call
What am I doing wrong?
I also tried
cal.rangeOfUnit(NSCalendarUnit.WeekCalendarUnit, startDate: startDate, interval: duration, forDate: now)
but it gives an error
"could not find an overload for 'rangeOfUnit' that takes the provided arguments.
source share