formatted(_:)
Generates a locale-aware string representation of an instance of person name components using the provided format style.
Declaration
func formatted<S>(_ style: S) -> S.FormatOutput where S : FormatStyle, S.FormatInput == PersonNameComponentsParameters
- style:
Specifies the Formatstyle applied to the person name components.
Return Value
A string, formatted according to the provided style.
Discussion
Use the formatted(_:) method to create a string representation of a person’s name with a customized length for specific uses. You can use the PersonNameComponents.FormatStyle static factory method name(style:) to create a custom format style as a parameter to the method.
For example:
var tlc = PersonNameComponents()
tlc.familyName = "Clark"
tlc.givenName = "Thomas"
tlc.middleName = "Louis"
tlc.namePrefix = "Dr."
tlc.nickname = "Tom"
tlc.nameSuffix = "Esq."
tlc.formatted(.name(style: .long))
// Dr. Thomas Louis Clark Esq.
tlc.formatted(.name(style: .medium))
// Thomas Clark
tlc.formatted(.name(style: .short))
// Tom
tlc.formatted(.name(style: .abbreviated))
// TC