NSAttributedString

  • Key

    Declaration

    Swift

    public extension NSAttributedString.Key
  • Creates a mutable copy

    Declaration

    Swift

    var asMutable: NSMutableAttributedString { get }
  • Undocumented

    Declaration

    Swift

    func addingAttributes(_ attributes: [NSAttributedString.Key : Any], to range: NSRange? = nil) -> NSAttributedString
  • Enumerates block contents in given range.

    Declaration

    Swift

    func enumerateContents(in range: NSRange? = nil) -> AnySequence<EditorContent>

    Parameters

    range

    Range to enumerate contents in. Nil to enumerate in entire string.

  • Enumerates only inline content in given range.

    Declaration

    Swift

    func enumerateInlineContents(in range: NSRange? = nil) -> AnySequence<EditorContent>

    Parameters

    range

    Range to enumerate contents in. Nil to enumerate in entire string.

  • Returns in range of CharacterSet from this string.

    Declaration

    Swift

    func rangeOfCharacter(from characterSet: CharacterSet) -> NSRange?

    Parameters

    characterSet

    CharacterSet to search.

  • Full range of this attributed string.

    Declaration

    Swift

    var fullRange: NSRange { get }
  • Collection of all the attachments with containing ranges in this attributed string.

    Declaration

    Swift

    var attachmentRanges: [AttachmentRange] { get }
  • Range of given attachment in this attributed string.

    Declaration

    Swift

    func rangeFor(attachment: Attachment) -> NSRange?

    Parameters

    attachment

    Attachment to find. Nil if given attachment does not exists in this attributed string.

  • Ranges of CharacterSet in this attributed string.

    Declaration

    Swift

    func rangesOf(characterSet: CharacterSet) -> [NSRange]

    Parameters

    characterSet

    CharacterSet to search.

  • Attributed substring in reverse direction.

    Declaration

    Swift

    func reverseAttributedSubstring(from range: NSRange) -> NSAttributedString?

    Parameters

    range

    Range for substring. Substring starts from location in range to number of characters towards beginning per length specified in range.

  • Gets the next range of attribute starting at the given location in direction based on reverse lookup flag

    Declaration

    Swift

    func rangeOf(attribute: NSAttributedString.Key, startingLocation location: Int, reverseLookup: Bool = false) -> NSRange?

    Parameters

    attribute

    Name of the attribute to look up

    location

    Starting location

    reverseLookup

    When true, look up is carried out in reverse direction. Default is false.

  • Gets the complete range of attribute at the given location. The attribute is looked up in both forward and reverse direction and a combined range is returned. Nil if the attribute does not exist in the given location

    Declaration

    Swift

    func rangeOf(attribute: NSAttributedString.Key, at location: Int) -> NSRange?

    Parameters

    attribute

    Attribute to search

    location

    Location to inspect

  • Gets the value of attribute at the given location, if present.

    Declaration

    Swift

    func attributeValue<T>(for attributeKey: NSAttributedString.Key, at location: Int) -> T?

    Parameters

    attributeKey

    Name of the attribute

    location

    Location to check

  • Alternative to attributedSubstring(from:_).string Avoids allocating NSAttributedString and all the attributes for that range, only to ignore the range.

    Declaration

    Swift

    func substring(from range: NSRange) -> String
  • Searches for given text in string

    Declaration

    Swift

    func reverseRange(of searchText: String, startingLocation: Int, isCaseInsensitive: Bool = true) -> NSRange?

    Parameters

    searchText

    Text to search

    startingLocation

    Starting location from which the text should be searched backwards

    isCaseInsensitive

    Case insensitive search. Defaults to true

    Return Value

    Range of search text, if found.