Generic Instance Method 総称体インスタンスメソッド

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 == PersonNameComponents

Parameters パラメータ

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

See Also 参照

Formatting Person Name Components