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

Viewed 541

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.

2 Answers

Go to your Target and click Edit Schemes and set your app language to "German" from option tab as ss below.

enter image description here

Related