ListParser
public struct ListParser
Provides helper function to convert between NSAttributedString
and [ListItem]
-
Parses an array of list items into an
NSAttributedString
representation.NewLines
are automatically added between each list item in the attributed string representation.Declaration
Swift
public static func parse(list: [ListItem], indent: CGFloat) -> NSAttributedString
Parameters
list
List items to convert
indent
Indentation 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
attributedString
NSAttributedString to convert to list items.
indent
Indentation 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
listIndex
denoting the index of list in the complete text. All items in the same list will have same index.listIndex
may be used to distinguish items of one list from another.