[Swift] ある月のすべてのNSDateを取得する

func getAllDateOfMonth(var year: Int, var month: Int) -> [NSDate] {
    var ret : [NSDate] = []
    var lastDay : Int
    var startDateOfMonth : NSDate?
    
    // 2. その月の最終日(UInt)を取得する
    var dateFormatter:NSDateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "yyyy/MM/dd"
    if month == 12 {
        month = 0
        year++
    }
    
    let beginningDateOfNextMonth : NSDate? = dateFormatter.dateFromString(String(format: "%04d/%02d/01", arguments: [year, month+1]))
    
    startDateOfMonth = calendar.dateByAddingUnit(NSCalendarUnit.CalendarUnitMonth, value: -1, toDate: beginningDateOfNextMonth!, options: nil)
    var lastDateOfThisMonth = NSDate(timeInterval: -24*60*60, sinceDate: beginningDateOfNextMonth!)
    let dateCompOfLastDate : NSDateComponents = calendar.components(NSCalendarUnit.CalendarUnitDay, fromDate: lastDateOfThisMonth)
    lastDay = dateCompOfLastDate.day
    
    // 3. 1-最終日、year, monthを使ってNSDateの配列をつくって返す
    for var i = 0; i < lastDay; i++ {
        ret.append(calendar.dateByAddingUnit(NSCalendarUnit.CalendarUnitDay, value: i, toDate: startDateOfMonth!, options: nil)!)
    }
    return ret
}