title: how to convert Range to NSRange in swift 4
body: <p>This is my swift 3 code:</p>
  
  <pre><code>extension String {
  
      func nsRange(from range: Range&lt;Index&gt;) -&gt; NSRange {
           let lower = UTF16View.Index(range.lowerBound, within: utf16)
           let upper = UTF16View.Index(range.upperBound, within: utf16)
           return NSRange(location: utf16.startIndex.distance(to: lower), length: lower!.distance(to: upper))
      }
  }
  </code></pre>
  
  <p>When i migrated to swift 4 it is giving me error distance(to:) is unavailable</p>
  
  <p>Any solution</p>