title: How do I access the properties of UITextField's selectedTextRange UITextPosition objects?
body: <p>I'm trying to establish the start and end positions of a text selection of a <code>UITextField</code> instance, using its <code>selectedTextRange</code> property (as gained from the <a href="https://developer.apple.com/documentation/uikit/uitextinput" rel="nofollow noreferrer"><code>UITextInput</code> protocol</a>). However, I have no idea how to access the properties of the <code>UITextPosition</code> objects that make up the <code>start</code> and <code>end</code> properties of <code>selectedTextRange</code>.</p>
  
  <p><a href="https://developer.apple.com/documentation/uikit/uitextposition" rel="nofollow noreferrer">Apple's docs on UITextPosition</a> are woeful at this time, providing no methods or properties, though I know there are such properties in the object, because NSLogging one gives this:</p>
  
  <pre><code>&lt;UITextPositionImpl: 0x6aaeb60&gt;
  &lt;&lt;WebVisiblePosition: 0x6aa40e0&gt;(offset=5, context=([s|a], [u+0073|u+0061])&gt;
  </code></pre>
  
  <p>In this example, the 'offset' is correct, and the context shows the characters either side of the selection point ('s' and 'a'), but I don't know how to access this nebulous <code>WebVisiblePosition</code> class. So, in short, is there a way of retrieving the details I want using <code>UITextPosition</code> objects from <code>UITextField</code>?</p>