title: Get character before cursor in Swift
body: <p>Yesterday I was working on <a href="https://stackoverflow.com/a/34922332/3681880">getting and setting the cursor position in a <code>UITextField</code></a>. Now I am trying to get the character just before the cursor position. So in the following example, I would want to return an "e".</p>
  
  <p><a href="https://i.stack.imgur.com/cg9we.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cg9we.png" alt="enter image description here"></a></p>
  
  <pre><code>func characterBeforeCursor() -&gt; String 
  </code></pre>
  
  <p>Notes</p>
  
  <ul>
  <li><p>I didn't see any other SO questions that were the same of this, but maybe I missed them.</p></li>
  <li><p>I wrote this question first and when I find an answer I will post both the question and the answer at the same time. Of course, better answers are welcomed.</p></li>
  <li><p>I said "character" but <code>String</code> is fine.</p></li>
  </ul>