[Solved] How to get number of weeks by month in year?


As already mentioned NSCalendar has a method rangeOfUnit:inUnit:forDate:.
The proper calendar units are CalendarUnitWeekOfYear and CalendarUnitMonth

The result might be different for the locale and first weekday of the week settings.

let calendar = NSCalendar.currentCalendar()
let weekRange = calendar.rangeOfUnit(NSCalendarUnit.CalendarUnitWeekOfYear, inUnit: .CalendarUnitMonth, forDate: NSDate())
let weekArray = Array(weekRange.location..<weekRange.location + weekRange.length)

Swift 3:

let calendar = Calendar.current
let weekRange = calendar.range(of: .weekOfYear, in: .month, for: Date())

1

solved How to get number of weeks by month in year?