title: Get cursor's position when enter key was pressed
body: <p>I would like to let user split UITextField when they press enter key in edit mode. Something like:</p>
  <blockquote>
  <p>foo|bar     (vertical bar being cursor) - now I press enter</p>
  </blockquote>
  <p>and I'd like to create new UITextField underneath, which should look like this:</p>
  <blockquote>
  <p>foo</p>
  <p>bar</p>
  </blockquote>
  <p>But I can't get cursor's position when I press enter. I tried this snippet:</p>
  <pre><code>    if let selectedRange = field.selectedTextRange {
          let cursorPosition = field.offset(from: field.beginningOfDocument, to: selectedRange.start)
          print(&quot;\(cursorPosition)&quot;)
      }
  </code></pre>
  <p>But it returns <code>6</code> instead of <code>3</code>. It appears pressing enter will make cursor jump to the end of current word first and then executing my snippet. I tried to put it in <code>textFieldShouldReturn</code>, <code>textFieldShouldEndEditing</code> and also in event of UITextField <code>Did End On Exit</code> with the same results.</p>
  <p>Is there a way to prevent the cursor's jump or is there some other way of solving it? I'm a beginner in iPhone development, so I may be missing something obvious...</p>