title: NSSortDescriptor evaluating ascending numbers (Swift)
body: <p>App has <code>contentid</code> coming in as a number string from a json file:</p>
  
  <pre><code>let contentid: AnyObject! = jsonFeed["contentid"]
  
  let stream:Dictionary = [
     "contentId": contentid as! String,
  ]
  </code></pre>
  
  <p>It is later saved to [NSManagedObject] with:</p>
  
  <pre><code>var articles = [NSManagedObject]()
  
  let entity =  NSEntityDescription.entityForName("Article", inManagedObjectContext: managedContext)
  let article = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext)
  
  article.setValue(stream["contentId"], forKey: "contentid")
  
  articles.append(article)
  </code></pre>
  
  <p>Finally, I use NSSortDescriptor to have Core Data return entries in numerical ascending order:</p>
  
  <pre><code>let sort = NSSortDescriptor(key: "contentid", ascending: true)
  fetchRequest.sortDescriptors = [sort]
  </code></pre>
  
  <p>But entries <strong>6</strong> - <strong>10</strong> are returned as: <strong>10, 6, 7, 8, 9</strong>. What would be the correct method of having these numbers evaluated correctly using NSSortDescriptor?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>For the Swift version, please see Volker's answer below. I ended up using:</p>
  
  <pre><code>let sort = NSSortDescriptor(key: "contentid", ascending: true, selector: "localizedStandardCompare:")
  </code></pre>
  
  <p>and it evaluated the numbered strings as true integers.</p>
  
  <p><strong>UPDATE: Swift 2:</strong></p>
  
  <p>Selector syntax has changed and no longer accepts objc pointers. Thank you user1828845.</p>
  
  <p><code>let sort = NSSortDescriptor(key: "contentid", ascending: true, selector: #selector(NSString.localizedStandardCompare(_:)))</code></p>