title: Get a range from a string
body: <p>I want to check if a string contains only numerals. I came across <a href="https://stackoverflow.com/a/23259654/1077789">this</a> answer written in Objective-C.</p>
  
  <pre><code>NSRange range = [myTextField.text rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]];
  if(range.location == NSNotFound) {
      // then it is numeric only
  }
  </code></pre>
  
  <p>I tried converting it to Swift. </p>
  
  <pre><code>let range: NSRange = username.rangeOfCharacterFromSet(NSCharacterSet.letterCharacterSet())
  </code></pre>
  
  <p>The first error I came across is when I assigned the type <code>NSRange</code>.</p>
  
  <p><strong>Cannot convert the expression's type 'Range?' to type 'NSRange'</strong></p>
  
  <p>So I removed the <code>NSRange</code> and the error went away. Then in the if statement,</p>
  
  <pre><code>let range = username.rangeOfCharacterFromSet(NSCharacterSet.letterCharacterSet())
  if range.location == NSNotFound {
  
  }
  </code></pre>
  
  <p>I came across the other error.</p>
  
  <p><strong>'Range?' does not have a member named 'location'</strong></p>
  
  <p>Mind you the variable <code>username</code> is of type <code>String</code> not <code>NSString</code>. So I guess Swift uses its new <code>Range</code> type instead of <code>NSRange</code>.</p>
  
  <p>The problem I have no idea how to use this new type to accomplish this. I didn't come across any documentation for it either.</p>
  
  <p>Can anyone please help me out to convert this code to Swift?</p>
  
  <p>Thank you.</p>