iOS中关于NSLocale的名称订购习惯

Jih*_*ang 4 ios nslocale

据我们所知,在英语国家,人们总是将他们的名字写成格式"FirstName MiddleName LastName",例如"Steven Paul Jobs".但是在某些其他语言中,它是不同的,例如,在中国,人们通常将名称写为"LastName FirstName"格式.我想在"NSLocale Class Reference"中找到一些东西,但它对我没什么帮助.我知道我可以通过NSLocaleCountryCode做"切换案例",但我不知道每个国家的习惯.那么,有没有更好的方法来解决名称订单问题?感谢帮助.

JMF*_*MFR 5

Foundation.framework中添加了此功能.兼容iOS9 +.

我还没有在文档中看到它,但它在头文件中,你可以在Swift Playground中使用它.

WWDC 2015 Session 227(大约22分钟)中介绍了此问题的详细信息.在本次会议中,他们讨论了NSPersonNameComponents和NSPersonNameComponentsFormatter.

例:

let components = NSPersonNameComponents()
components.namePrefix = "Mrs."
components.givenName = "Grace"
components.middleName = "Murray"
components.familyName = "Hopper"

NSPersonNameComponentsFormatter.localizedStringFromPersonNameComponents(
    components, style: .Default, options: [])
Run Code Online (Sandbox Code Playgroud)