Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

viewDidAppear

macrumors newbie
Original poster
Sep 9, 2021
1
0
Hi all,

I've been around in these circles for over 10 years, but I'm starting to get back into the online forum circles. Just thought this would be a good share!

Swift:
// Example 1

let formatter = PersonNameComponentsFormatter()
formatter.style = .long

let components = formatter.personNameComponents(from: "Mac Rumors")
print(components!.givenName!) // Mac
print(components!.familyName!) // Rumors

// Example 2

var formatter = PersonNameComponents()
formatter.familyName = "Rumors"
formatter.givenName = "Mac"
print(formatter) // "firstname: Mac familyname: Rumors"

When you work with any major apps, you often need to deal with customer's names. It's not safe to assume that every user follows the western First/Last conventions. For example, I'm Australian but I live in Japan, and we format names Last/First.

Sometimes attention not being paid to this can lead to problems. I discovered this, and I thought I'd share.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.