Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name order habit in iOS about NSLocale

Tags:

ios

nslocale

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.

like image 534
Jihang Yang Avatar asked Dec 24 '22 15:12

Jihang Yang


1 Answers

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: [])
like image 90
JMFR Avatar answered Dec 31 '22 12:12

JMFR