Request caretRectForPosition: while NSTextStorage has outstanding changes

I am getting an error recently:

requesting caretRectForPosition: while the NSTextStorage has oustanding changes {x, x} 

* "Alienation" is literally what he says, and this is not my typo.

This is called when I repeat through an NSTextStorage subclass of NSTextView using the enumerateAttribute() method and manipulating NSTextAttachment 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 like this one seem to be online, but I haven't managed to find any occurrences in this case yet and it seems to only apply to iOS 9.

This only happens when using the physical keyboard on the iPad.

+5
source share
2 answers

This happens if you call caretRectForPosition (or any method that calls such as firstRectForRange ) when the text store has changes.

I was able to prevent these logs by postponing some things until endEditing was called in NSTextStorage and dispatch_async in the main queue to do my job. Asynchronization does not show any visible flashes of the user interface or anything.

There should be a better way to solve this problem, but that’s all I could understand.

+5
source

God, I'm just solving the problem right now. You must own your warehouse in other ways. just trust me and try.

-3
source

Source: https://habr.com/ru/post/1237229/


All Articles