It's 8th of October, 2017, Sunday.
var weekday = Calendar(identifier: .iso8601).component(.weekday, from: Date())
weekday is 1, but should be 7. What's the problem?
It's 8th of October, 2017, Sunday.
var weekday = Calendar(identifier: .iso8601).component(.weekday, from: Date())
weekday is 1, but should be 7. What's the problem?
First of all: This has nothing to do with Swift. NSCalendar
is a part of Cocoa. (And written in Objective-C, by the way.)
In general:
Even in most western countries the "business week" starts with monday (aka 1st day of week), traditionally in hebrew and christian calendar the sunday is the first day of week. (Beside this, for christians it is the day of god. Of course, this is the first day. Can you give god another place?)
Therefore it is quite usual to get 1 or 0 (aka the lowest valid index) for sunday on western calendars.
ISO8601
However, ISO8601 positively defines the monday as the first day of a week. But this has nothing to do with indexing the weekdays, but with calculating with weeks, i. e. for "first week of a year". weekday
is a simple index, nothing else.