Skip to content

About ClosedRange's extension and AttributedString #43

Description

@MrYu4

As the code says in ClosedRange+NSRange:

    var nsRange: NSRange { return .init(location: first ?? 0, length: last ?? 0) }

and it's used in AttributedString.swift this function

 @discardableResult
    func addAttribute(_ attr: NSAttributedString.Key, _ value: Any, at range: ClosedRange<Int>? = nil) -> AttributedString {
        // TODO: check range
        let range = range ?? 0..._attributedString.length
        _attributedString.addAttribute(attr, value: value, range: range.nsRange)
        _updateHandler?(_attributedString)
        return self
    }

I'm a bit confuse for how I configured the 'range' such as 23 to 24 because I can't pass 23...24 which means it start at 23 but length is 24 or 23...1 which the first should be smaller or equal the last. I need your help.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions