Search code examples
swiftdateformatter

Swift: Why is DateFormatter using locale "en" when my device is set to "de" and my Scheme is set to "System Language"


My iPhone is set to German. My Debug Scheme App Language Setting is set to System Language. Still I have to manually apply the formatter.locale... otherwise I get "Tuesday" instead of "Dienstag". Of course I don't want to set the locale manually. I want the output to be localized to whatever the user chose.

func weekday(forDate day: Date) -> String {
    let formatter = DateFormatter()
    //formatter.locale = Locale.current // gives me locale en
    formatter.locale = Locale(identifier: "de") //without this line I get locale en
    formatter.setLocalizedDateFormatFromTemplate("E")
    return formatter.string(from: day)
}

Are there settings that I don't know about that override the settings I mentioned?

PS: in Playgrounds the locale is correct.

PPS: On my Mac the Simulator's locale is set to en although my Mac system is set to German. Don't know why, didn't mind much yet. What bothers me is that on the iPhone it's not respecting the locale.


Solution

  • I solved the problem by finally finding this post: How do I change the Development language in Xcode before internationalizing my app?

    I had to manually edit project.pbxproj inside the .xcodeproj and set the development region to German:

    developmentRegion = de;
    

    Now it works without specifying the locale in code and while keeping Scheme set to "System Language".