title: How to convert Range in NSRange?
body: <p>I am updating my code in swift 3. Getting error in converting Range into NSRange. How to do that in swift 3 ? </p>
  
  <pre><code>func nsRange(_ range : Range&lt;String.Index&gt;) -&gt; NSRange {
      let utf16from = String.UTF16View.Index(range.lowerBound, within: utf16)
      let utf16to   = String.UTF16View.Index(range.upperBound,   within: utf16)
      return NSRange(location: utf16.startIndex.distanceTo(utf16from), length: utf16from.distanceTo(utf16to))
  }
  </code></pre>