Sunday, November 27, 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 // Identical as doing Locale(identifier: "Some Invalid Identifier")
print(df.locale)

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

Non-compulsory(en_US (present))

So even when the locale is about 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:

Non-compulsory(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