Khant Thu Linn Khant Thu Linn - 9 months ago 39
iOS Question

Checking out of bounds for attributedSubstringFromRange

I have simple method like this.

NSAttributedString *aStr = [self.attributedText attributedSubstringFromRange:range];

But sometimes, it show error 'out of bounds'. How can I check beforehand? Do I only check .length ? Is there alternative way?


You need the following check:

range.location + range.length <= self.attributedText.length