To use an invariant NSLocale in iOS we create a locale object using the LocaleID "en_US_POSIX". Where is this string constant defined in the iOS Cocoa or Foundation libraries? Would like to stop defining it myself in apps
Asked
Active
Viewed 2,268 times
3
-
What constants are you referring to? There are no constants for any locale ids. – rmaddy Jan 05 '18 at 21:29
-
I don't believe this string literal is defined as a constant anywhere. If you don't like setting this locale yourself, you can use [`NSISO8601DateFormatter`](https://developer.apple.com/documentation/foundation/nsiso8601dateformatter) (called `ISO8601DateFormatter` in Swift), and it uses this locale automatically without having to specify it. – Rob Jan 05 '18 at 21:36
-
1@rmaddy referring to creating an NSLocale via Locale ID. To make the invariant locale you use a string "en_US_POSIX". Other languages and platforms have this concept as a first class citizen (ex .NET Culture.Invariant) – stonedauwg Jan 05 '18 at 21:46
-
1@Rob This isnt about date formatting - just in general. There are all kinds of reasons and APIs that need the iOS locale info and for invariant there seems to be no way to grab it other than create yourself an even then no const defined – stonedauwg Jan 05 '18 at 21:49
-
1@stonedauwg I know all about NSLocale and locale ids. I'm asking you what constants you are referring to. There are no constants for any locale ids in Swift or Objective-C. You pass a string, that's it. If you don't want to type "en_US_POSIX" more than once, create your own constant. – rmaddy Jan 05 '18 at 21:54