style
Specifies the style of the formatted result.
Declaration
var style: PersonNameComponents.FormatStyle.StyleDiscussion
The style property controls length of the string representation of the name.
For example:
var tlc = PersonNameComponents()
tlc.familyName = "Clark"
tlc.givenName = "Thomas"
tlc.middleName = "Louis"
tlc.namePrefix = "Dr."
tlc.nickname = "Tom"
tlc.nameSuffix = "Esq."
let longFormatStyle = PersonNameComponents.FormatStyle(style: .long, locale: Locale(identifier: "us_EN"))
print(tlc.formatted(longFormatStyle)) // Dr. Thomas Louis Clark Esq.
let mediumFormatStyle = PersonNameComponents.FormatStyle(style: .medium, locale: Locale(identifier: "us_EN"))
print(tlc.formatted(mediumFormatStyle)) // Thomas Clark
let shortFormatStyle = PersonNameComponents.FormatStyle(style: .short, locale: Locale(identifier: "us_EN"))
print(tlc.formatted(shortFormatStyle)) // Tom
let abbrevFormatStyle = PersonNameComponents.FormatStyle(style: .abbreviated, locale: Locale(identifier: "us_EN"))
print(tlc.formatted(abbrevFormatStyle)) // TC
let defaultFormatStyle = PersonNameComponents.FormatStyle(locale: Locale(identifier: "us_EN"))
print(tlc.formatted(defaultFormatStyle)) // Thomas ClarkThe default value is medium.
Styles
You can configure PersonNameComponents.FormatStyle to format names in the following styles:
mediumThe minimally necessary features for differentiation in a casual setting.
shortRelies on user preferences and language defaults to display shortened form appropriate in space-constrained settings.
longThe fully-qualified name complete with all known components.
abbreviatedThe maximally abbreviated form of a name.
The following table demonstrates the style for various names and locales.
Locale | Name prefix | Given name | Middle name | Family name | Name suffix | Nickname |
|---|---|---|---|---|---|---|
Arabic [Image] | .د | أحمد | محمدالمصري | |||
Chinese [Image] | 物理学博士 | 振宁 | 杨 | 先生 | ||
English [Image] | Dr. | Thomas | Louis | Clark | Esq. | Tom |
French [Image] | Père | Jean-Philippe | de Zélicourt | JP | ||
German [Image] | Dr. med. | Max | Mustermann | junior, M.A. | ||
Hindi [Image] | डॉ. | रिय | साहिल | |||
Japanese [Image] | 泰夫 | 木田 | 先生 | |||
Spanish [Image] | Dr. | José Ramiro | Martín González de Rivera | júnior, PhD | Ramiro | |
Thai [Image] | ฯพณฯ | สมชาย | ปีเตอร์ | รัตนเรืองรองบวรทิพย์ |
Long
The Long style provides the most explicit representation of names. It uses all available name components, with the exception of nickname.
Locale | Long style |
|---|---|
Arabic (ar-SA) | ﺩ. أحمد محمﺩﺍلمصﺭﻱ |
Chinese (zh-Hans) | 物理学博士杨振宁先生 |
English (en-US) | Dr. Thomas Louis Clark Esq. |
French (fr-FR) | Père Jean-Philippe de Zélicourt |
German (de-DE) | Dr. med. Max Mustermann junior, M.A. |
Hindi (hi-IN) | डॉ. रिय साहिल |
Japanese (ja-JP) | 木田泰夫先生 |
Spanish (es-ES) | Dr. José Ramiro Martín González de Rivera júnior, PhD |
Thai (th-TH) | ฯพณฯ สมชาย ปีเตอร์ รัตนเรืองรอง บวรทิพย์ |
Medium
The Medium, or default, style presents names in a way that is suitable for most contexts. It uses the given and family names, as well as a nickname, if provided, and enabled by the user.
Locale | Default style |
|---|---|
Arabic (ar-SA) | أحمد محمﺩﺍلمصﺭﻱ |
Chinese (zh-Hans) | 杨振宁 |
English (en-US) | Thomas Clark |
French (fr-FR) | Jean-Philippe de Zélicourt |
German (de-DE) | Max Mustermann |
Hindi (hi-IN) | रिय साहिल |
Japanese (ja-JP) | 木田泰夫 |
Spanish (es-ES) | José Ramiro Martín González de Rivera |
Thai (th-TH) | สมชาย รัตนเรืองรอง บวรทิพย์ |
Short
The Short style offers an alternative display method for names whose default representation may exceed a certain length constraint. Users customize how the system displays short names in the preferences for the Contacts app. For scripts that don’t support Short name, or cases where the specified Short style is unavailable, the format uses Medium style.
The table below shows the formatted string output for each Short Name configuration and for a variety of locales:
Locale | Given name - family initial | Given initial - family name | Given name only | Family name only |
|---|---|---|---|---|
Arabic (ar-SA) | N/A | N/A | أحمد | محمﺩﺍلمصﺭﻱ |
Chinese (zh-Hans) | N/A | N/A | N/A | N/A |
English (en-US) | Thomas C | T Clark | Thomas | Clark |
French (fr-FR) | Jean-Philippe d | J de Zélicourt | Jean-Philippe | de Zélicourt |
German (de-DE) | Max M | M Mustermann | Max | Mustermann |
Hindi (hi-IN) | N/A | N/A | रिय | साहिल |
Japanese (ja-JP) | N/A | N/A | N/A | N/A |
Spanish (es-ES) | José Ramiro M | J Martín González de Rivera | José Ramiro | Martín González de Rivera |
Thai (th-TH) | สมชาย ร | ส รัตนเรืองรองบวรทิพย์ | สมชาย | รัตนเรืองรองบวรทิพย์ |
Abbreviated
The Abbreviated style offers the most compact representation of names, similar to a monogram.
Abbreviated style is supported for names in several scripts, with the following general characteristics:
For names in Cyrillic, Greek, or Latin script, the first characters of
givenName,middleName, andfamilyNamemay be used.For names in Chinese or Japanese script,
familyNamemay be used. IffamilyNameis too long, or if the family name isnil, the Short or Medium style may be used instead.For names in Korean script,
givenNamemay be used. IfgivenNameis too long, the first character ofgivenNamemay be used. IfgivenNameisnil, thefamilyNamemay be used instead.For names in Bengali, Devanagari, Gujarati, Gurmukhi, Kannada, Malayalam, Oriya, Sinhala, Tamil, Telugu, Tibetan, or Thai script, the first character of
givenNamemay be used. IfgivenNameisnil, the first character offamilyNamemay be used instead.For names that contain more than one script, the abbreviated style may use the
familyName,givenName, or the first characters ofgivenNameand/orfamilyName.
If the Abbreviated style is unavailable, the Short style is used instead—unless that too is unsupported, in which case the Medium style is used instead.
Locale | Abbreviated style |
|---|---|
Arabic (ar-SA) | N/A |
Chinese (zh-Hans) | 杨 |
English (en-US) | TLC |
French (fr-FR) | Jd |
German (de-DE) | MM |
Hindi (hi-IN) | मि |
Japanese (ja-JP) | 木田 |
Spanish (es-ES) | JM |
Thai (th-TH) | ส |