ListItemFormatter
@objc(LNListItemFormatter)
public class ListItemFormatter : Formatter, NSSecureCoding
ListItemFormatter can be used to format variable-length lists of things in a locale-sensitive manner, such as “Monday, Tuesday, Friday, and Saturday” (in English) versus “lundi, mardi, vendredi et samedi” (in French).
-
The following constants specify predefined format modes for list items.
The mode is used in conjuction with the
See moreStyleto pick the most appropriate set of patterns used by the formatter. You can read more about the patterns in the Unicode documentation.Declaration
Swift
@objc(LNListItemFormatterMode) public enum Mode : Int -
The style is used in conjuction with the
See moreModeto pick the most appropriate set of patterns used by the formatter. You can read more about the patterns in the Unicode documentation.Declaration
Swift
@objc(LNListItemFormatterStyle) public enum Style : Int -
The format mode of the receiver.
The default value is set to
.standard.Declaration
Swift
@objc public var mode: Mode -
The format style of the reciever.
The default value is set to
.default.Declaration
Swift
@objc public var style: Style -
The locale for the receiver.
The default value is set to
Locale.autoupdatingCurrent.Declaration
Swift
@objc public var locale: Locale -
The default text attributes used to display the output string.
The value of this property is used by the receiver to produce the output
NSAttributedStringobject ofListItemFormatter.attributedString(from:).The default value is an empty dictionary.
Declaration
Swift
@objc public var defaultAttributes: [NSAttributedString.Key : Any] -
The item specific attributes used to display the list items within the output string.
The value of this property is used by the receiver to produce the output
NSAttributedStringobject ofListItemFormatter.attributedString(from:), specifically by applying these attributes only to the items within thelistarray. These attributes are applied on top ofdefaultAttributes.The default value of this property is an empty dictionary.
Declaration
Swift
@objc public var itemAttributes: [NSAttributedString.Key : Any] -
Returns a string representation of the given list items formatted using the receiver’s current settings.
Declaration
Swift
@objc(stringFromList:) public func string(from list: [String]) -> StringParameters
listThe list items to be formatted into a localised, human readable list.
Return Value
A string representation of
listformatted using the receiver’s current settings. -
Returns an attributed strign representation of the given list items formatted using the receiver’s current settings.
The receiver uses the values set in its
defaultAttributesanditemAttributesproperties by first applying the default attributes to the entire string and then addingitemAttributesto the range of each item withinlist. This means that attributes in the default attributes will first be applied to thelistitem ranges and then will be overwritten with values from the item specific attributes if they conflict. This means that you do not need to set the same attributes twice.Declaration
Swift
@objc(attributedStringFromList:) public func attributedString(from list: [String]) -> NSAttributedStringParameters
listThe list items to be formatted into an attributed, localised, human readable list.
Return Value
An attributed string representation of
listformatted using the receiver’s current settings.
View on GitHub
ListItemFormatter Class Reference