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 Style to pick the most appropriate set of patterns used by the formatter. You can read more about the patterns in the Unicode documentation.

    See more

    Declaration

    Swift

    @objc(LNListItemFormatterMode)
    public enum Mode : Int
  • The style is used in conjuction with the Mode to pick the most appropriate set of patterns used by the formatter. You can read more about the patterns in the Unicode documentation.

    See more

    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 NSAttributedString object of ListItemFormatter.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 NSAttributedString object of ListItemFormatter.attributedString(from:), specifically by applying these attributes only to the items within the list array. These attributes are applied on top of defaultAttributes.

    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]) -> String

    Parameters

    list

    The list items to be formatted into a localised, human readable list.

    Return Value

    A string representation of list formatted 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 defaultAttributes and itemAttributes properties by first applying the default attributes to the entire string and then adding itemAttributes to the range of each item within list. This means that attributes in the default attributes will first be applied to the list item 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]) -> NSAttributedString

    Parameters

    list

    The list items to be formatted into an attributed, localised, human readable list.

    Return Value

    An attributed string representation of list formatted using the receiver’s current settings.