I notice there are several ways to construct NSRange
let range = NSRange(location: 0, length: attributedString.length)
attributedString.addAttribute(..., range: range)
and
let range = NSRange(location: 0, length: attributedString.string.utf16.count)
attributedString.addAttribute(..., range: range)
I was wondering, is attributedString.length
always equivalent to attributedString.string.utf16.count
?
So far, I can't find out any case when they are different.
Is there a situation when they are not?
CodePudding user response:
yes, they're the same. According to Apple's document NSAttributedString.length is The number of UTF-16 code units in the receiver.
Then
attributedString.length = attributedString.string.utf16.count
https://developer.apple.com/documentation/foundation/nsattributedstring/1418432-length