Sunday, December 4, 2022
HomeiOS Developmentios - What occurs in DateFormetter when Locale is initialized with an...

ios – What occurs in DateFormetter when Locale is initialized with an invalid identifier?


It defaults to Locale.present. Strive the next code in a Playground:

let df = DateFormatter()
df.locale = nil // Similar as doing Locale(identifier: "Some Invalid Identifier")
print(df.locale)

The output for me (I am within the USA) is:

Optionally available(en_US (present))

So even when the locale is ready to nil (which is what you get with an invalid locale identifier), it nonetheless returns the present locale.

As a check I modified my pc’s area to Canada after which the output of the code was:

Optionally available(en_CA (present))

Additional proof that it defaults to the present locale and never en_US or en_US_POSIX.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments