ListParser
public struct ListParser
Provides helper function to convert between NSAttributedString and [ListItem]
-
Parses an array of list items into an
NSAttributedStringrepresentation.NewLinesare automatically added between each list item in the attributed string representation.Declaration
Swift
public static func parse(list: [ListItem], indent: CGFloat) -> NSAttributedStringParameters
listList items to convert
indentIndentation to be used. This determines the paragraph indentation for layout.
Return Value
NSAttributedString representation of list items
-
Parses NSAttributedString to list items
Note
If NSAttributedString passed into the function is non continuous i.e. contains multiple lists, the array will contain items from all the list with the range corresponding to range of text in original attributed string.Declaration
Swift
public static func parse(attributedString: NSAttributedString, indent: CGFloat = 25) -> [(listIndex: Int, range: NSRange, listItem: ListItem)]Parameters
attributedStringNSAttributedString to convert to list items.
indentIndentation used in list representation in attributedString. This determines the level of list item.
Return Value
Array of list items with corresponding range in attributedString along with
listIndexdenoting the index of list in the complete text. All items in the same list will have same index.listIndexmay be used to distinguish items of one list from another.
View on GitHub
ListParser Structure Reference