title: Swift : How to get the string before a certain character?
body: <p>How do I get the string before a certain character in swift? The code below is how I did it in Objective C, but can't seem to perform the same task in Swift. Any tips or suggestions on how to achieve this? <code>rangeOfString</code> seems to not work at all in swift (although Swift has been acting up for me again).</p>
  
  <pre><code>NSRange range = [time rangeOfString:@" "];
  NSString *startDate =
  [time substringToIndex:range.location];
  </code></pre>
  
  <p>As you can see from the code above I am able to get the string before the space character in Objective C.</p>
  
  <p>Edit : If I try something like this </p>
  
  <pre><code> var string = "hello Swift"
   var range : NSRange = string.rangeOfString("Swift")
  </code></pre>
  
  <p>I get the following error. </p>
  
  <blockquote>
    <p>Cannot convert the expression's type 'NSString' to type '(String,
    options: NSStringCompareOptions, range: Range?, locale:
    NSLocale?)'</p>
  </blockquote>
  
  <p>Not sure what I did wrong exactly or how to resolve it correctly.</p>