In my playground, Calendar.current.firstWeekday == 1, which I interpret as
"Monday is the first day of the week where I live (Sweden)"
But when I run the simulator, Calendar.current.firstWeekday == 2, and I don't understand why! (In the simulator's settings I have set the region to "Sweden").
let c = Calendar.current
print(c) // prints "gregorian"
let first = Calendar.current.firstWeekday // this is 2 !!!
Question: Why is Calendar.current.firstWeekday == 2 and how can I fix this?
which I interpret as
I believe your interpretation is wrong. I'm not sure how the framework assigns the days of the week, but from your question I believe that they go 1 through 7, where 1 is Sunday, 2 is Monday and so on. These are static and don't change with your settings.
The firstWeekday
property tells you what day of the week the week starts in your locale. In the US, which is the default locale, a week starts on Sunday.
You can't "fix this" because nothing is wrong, that property is there to provide you with information which is specially useful when drawing a calendar.
In the playground, the locale is set, as a default, to the US localization. Hence, it says that the first day of the week is 1/Sunday, which is the case in the US.
When you ran the code in the simulator, that HAD been set to Sweeden, you're told that the first day of the week is 2/Monday, which is the case in Sweden.
The discrepancy is due to the fact that the playground defaults to a US localization. If you'd like the playground to act as though it is in Sweden, you'll have to put that in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With