I've been recently getting the error:
requesting caretRectForPosition: while the NSTextStorage has oustanding changes {x, x}
* "Oustanding" is literally what it says, and is not my typo.
This is being called when I am iterating through the NSTextStorage
of a subclass of NSTextView
with the enumerateAttribute()
method and manipulating the NSTextAttachment
s in the text view after every change in the text view.
func manipulateText() {
let text = customTextView.textStorage
text.enumerateAttribute(NSAttachmentAttributeName, inRange: NSMakeRange(0, text.length), options: NSAttributedStringEnumerationOptions(rawValue: 0)) {
//
}
}
extension ThisViewController: UITextViewDelegate {
func textViewDidChange(textView: UITextView) {
manipulateText()
}
}
Questions such as this seem to be online, but I have yet to find any occurrences of this and seems to be relevant to iOS 9 only.
This only happens when using a physical keyboard on iPad.
This happens if you call caretRectForPosition
(or any method that calls that like firstRectForRange
) while the text storage has edits.
I was able to prevent these logs by deferring some stuff until after endEditing
is called in the NSTextStorage and dispatch_async
to the main queue to do my work. There aren't any visible UI flashes or anything as a result of the async.
There has to be a better way to solve this, but this is all I could figure out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With