NSAttributedString get attributes out of bounds exception

Viewed 2106

I'm trying to get attributes from attributed string. Everything is ok unless string is empty. Take a look:

let s = NSAttributedString(string: "", attributes: [NSForegroundColorAttributeName: UIColor.red])
let range = NSMakeRange(0, s.length)
let attrs = s.attributes(at: 0, longestEffectiveRange: nil, in: range)

Why I'm getting Out of bounds exception on last line?

2 Answers
Related