Type MethodFoundationEssentials
list(memberStyle:type:width:)
static func list<MemberStyle, Base>(memberStyle: MemberStyle, type: ListFormatStyle<MemberStyle, Base>.ListType, width: ListFormatStyle<MemberStyle, Base>.Width = .standard) -> Self where Self == ListFormatStyle<MemberStyle, Base>, MemberStyle : FormatStyle, Base : Sequence, MemberStyle.FormatInput == Base.Element, MemberStyle.FormatOutput == String
Parameters
memberStyleThe format style to apply to each item in the list.
typeThe list type to apply, such as cumulative (
ListFormatStyle.ListType.and) or alternative (ListFormatStyle.ListType.or) elements.widthThe width to use when formatting, such as
ListFormatStyle.Width.standardorListFormatStyle.Width.narrow.
Return Value
A list format style that formats an array as a textual list of items.
Discussion
Use the dot-notation form of this type method when the call point allows the use of ListFormatStyle. You typically do this when calling the formatted method of Sequence.
The following example creates an array of integers, then uses the list format style provided by this method to format the items. By using a currency IntegerFormatStyle, the list format style expresses each member as US dollars.
let items: [Int] = [100, 1000, 10000, 100000, 1000000]
let formatted = items.formatted(
.list(memberStyle: .currency(code: "USD"),
type: .and)
.locale(Locale(identifier: "en_US"))) // "$100.00, $1,000.00, $10,000.00, $100,000.00, and $1,000,000.00"