Created
September 8, 2021 19:05
-
-
Save krzyzanowskim/3fca98a926b8943f646a8dfdc2625aae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let formatter = PersonNameComponentsFormatter() | |
formatter.style = .long | |
do { | |
let components = formatter.personNameComponents(from: "Marcin Krzyżanowski")! | |
print(components.givenName!) // Marcin | |
print(components.familyName!) // Krzyżanowski | |
} | |
do { | |
let components = formatter.personNameComponents(from: "Krzyżanowski Marcin")! | |
print(components.givenName!) // Marcin | |
print(components.familyName!) // Krzyżanowski | |
} | |
do { | |
var components = PersonNameComponents() | |
components.givenName = "Marcin" | |
components.middleName = "the Great" | |
components.familyName = "Krzyżanowski" | |
let name = formatter.string(from: components) | |
print(name) // Marcin the Great Krzyżanowski | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting what it gets right and what it doesn't.