I'm trying to write tests for a piece of code I wrote that converts dates to en_US_POSIX using an NSDateFormatter. The tests seem to launch an iOS simulator when running, and changing the language here seems to also change the language used when running a test.
Is there a way I can programmatically set the emulator's language so that a particular test (or test suite) will be in the proper language I want to test with?
[UPDATE] I've tried using the "-AppleLanguages" and "-AppleLocales" parameters for my scheme, but neither seem to affect the language during test runs - [[NSLocale currentLocale] localeIdentifier]
still returns en_US
, and [NSDate date]
still outputs as a normal yyyy-MM-dd HH:mm:ss ZZZ
format.
[UPDATE] I don't believe this is a duplicate. The article cites changing the language in Settings not having any effect, but I can do this in my simulator and see the keyboard language change in my App. The issue revolves around a simple call to [NSDate date] always returning the date in an en_UTC-style format, regardless of using a language with a non-Roman character set, like Arabic.
[Solved] I've found the solution. Apparently, the output of functions like [NSDate date]
is determined by the system LOCALE, not the language. Removing the -AppleLanguages argument and replacing it with -AppleLocale ar_AE
caused the output of [NSDate date]
to appear in Arabic, which is what I'm looking for.