MihaelIsaev / UIKitPlus

🏰 Declarative UIKit with LivePreview for iOS9+ (best alternative to SwiftUI)
MIT License
596 stars 35 forks source link

About ClosedRange's extension and AttributedString #43

Open MrYu4 opened 3 months ago

MrYu4 commented 3 months ago

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.