As far as we know that in English speaking country, people always write their names down as format "FirstName MiddleName LastName", such as "Steven Paul Jobs". However in some other language, it is different, for example, in China, people usually write name as "LastName FirstName" format. I want to find out something in "NSLocale Class Reference" but it did not help me a lot. I know that I can do "switch case" by NSLocaleCountryCode, but I do not know every country's habit. So, is there any better way to solve the name order issues? Thanks for help.
This functionality has been added in Foundation.framework. Compatible with iOS9+.
I do not see it in the documentation yet but it is in the header files and you can use it in a Swift Playground.
The details of this problem are covered in WWDC 2015 Session 227 (about 22 minutes in). In this session they talk about an NSPersonNameComponents and NSPersonNameComponentsFormatter.
Example:
let components = NSPersonNameComponents()
components.namePrefix = "Mrs."
components.givenName = "Grace"
components.middleName = "Murray"
components.familyName = "Hopper"
NSPersonNameComponentsFormatter.localizedStringFromPersonNameComponents(
components, style: .Default, options: [])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With