How can I take an array with days of week from the system (from NSDate
, I think)?
Until now, I can only take the current day, but I'd like to be able to take all weekdays in an array.
If the first day of week is set to Monday, my array would look like:
[ Mon, Tue, Wed... ]
If the first day of week is Sunday, my array would look like:
[Sun, Mon, Tue... ]
Code:
let dateNow = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | .CalendarUnitYear , fromDate: dateNow)
/*This is the way how i take system time */
let format = NSDateFormatter()
format.dateFormat = "EEE"
stringDay = format.stringFromDate(dateNow)
Calendar.current.firstWeekDay
in later Swift versions instead of providing it manually. – Daviddavida