Kris
Kris

Reputation: 155

NSCalendar firstWeekday always 1 regardless of user preference

I am attempting to get the firstWeekday as set in the user's system preferences, using [[NSCalendar currentCalendar] firstWeekday], however the value returned is always 1 (Sunday) regardless of what is set in the system preferences. Also tried the autoupdatingCurrentCalendar with the same results.

From the docs, it states [NSCalendar currentCalendar] returns a calendar formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences. From that description it sounds like I should be able to access the firstWeekday set in the user settings.

Anyone have any ideas as to why this is not returning the correct firstWeekday?

Upvotes: 4

Views: 234

Answers (1)

Warpling
Warpling

Reputation: 2095

Here's the deal…

Changing the first weekday in Settings > Calendar > First Weekday ONLY adjusts the day weeks start on in Apple's Calendar app. It does NOT adjust underlying NSCalendar objects. To do that you'll have to change your phone's region under Settings > General > Date & Time > Language & Region > Region to something like Germany to test a calendar with the start of the week as Monday, or US for Sunday, etc.

(To anyone setting out to work on calendar based code: thank you for caring about localization and also here be dragons. Good luck!)

Upvotes: 1

Related Questions