title: Get currently typed word in UITextView
body: <p>I'm trying to make a "tagging window" much like the one used in Facebook where you type "@" and it make suggestions among your friends on which one to tag. I'd like this feature in my app, but I can't for the life of me figure out how to get the currently typed word in order to filter suggestions.</p>
  
  <p>I use an <code>UITextView</code> and I've been looking at this post <a href="https://stackoverflow.com/a/27380612/4148782">https://stackoverflow.com/a/27380612/4148782</a></p>
  
  <p>but I have issues translating this to Swift 3, and even so the comments suggests that this isn't solved anyway.</p>
  
  <p>So the functionality I'm after is: </p>
  
  <ul>
  <li>User starts typing in a <code>UITextView</code> and if the word begins with a "@" I'd like to extract the word.</li>
  <li>I'd like to replace the word with a certain input as well. Let's say the user types <strong>@abc</strong> and I filter a suggestion which states "<strong>abcdef</strong>", then I want to be able to replace the <strong>@abc</strong> in the UITextView with "<strong>abcdef</strong>".</li>
  </ul>
  
  <p>Note that I want the word <strong>currently</strong> getting typed and <strong>not</strong> the most recent typed word.</p>