title: How to efficiently find CGRects for visible words in UITextView?
body: <p>My goal is to mark all visible misspelled words in an UITextView. </p>
  
  <p>The inefficient algorithm is to use the spell checker to find all ranges of misspelled words in the text, convert them to UITextRange objects using positionFromPosition:inDirection:offset etc, then get the graphics rects using the UITextInput method firstRectFromRange.</p>
  
  <p>Thus all the text -> misspelled words-> NSRange collection -> UITextRange collection -> CGRect collection -> evaluate for visibility, draw visible ones</p>
  
  <p>The problem is that this requires that all the text is checked, and all misspelled words are converted to graphics rects.</p>
  
  <p>Thus, I imagine the way to go is to somehow find out what parts of the underlying .text in the UITextView that is visible at the moment.</p>
  
  <p>Thus for range of text visible -> misspelled words-> NSRange collection -> UITextRange collection -> CGRect collection -> evaluate for visibility, draw visible ones</p>
  
  <p>The code in <a href="https://stackoverflow.com/questions/6067803/ios-how-to-find-what-is-the-visible-range-of-text-in-uitextview">ios - how to find what is the visible range of text in UITextView?</a> might work as a way to bound what parts of the text to check, but still requires that all text is measured, which I imagine could be quite costly.</p>
  
  <p>Any suggestions?</p>