title: Swift - Sorting an array retrieved from Core Data
body: <p>I want to sort the array with usernames that I retrieve from my core data. I retrieve it like this:</p>
  
  <pre><code>override func viewDidAppear(animated: Bool) {
  
      let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
      let context:NSManagedObjectContext = appDel.managedObjectContext!
      let freq = NSFetchRequest(entityName: "User")
      let en = NSEntityDescription.entityForName("User", inManagedObjectContext: context)
  
      myList = context.executeFetchRequest(freq, error: nil)!
  
      tv.reloadData()
  
  }
  </code></pre>
  
  <p>And later I set the cells in my tableview like this:</p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      let CellID:NSString = "cell"
      var cell: UITableViewCell = self.tv.dequeueReusableCellWithIdentifier(CellID) as UITableViewCell
      if let ip = indexPath as Optional {
  
          var data:NSManagedObject = myList[ip.row] as NSManagedObject
  
          cell.textLabel!.text = data.valueForKeyPath("username") as String!
  
      }
  </code></pre>
  
  <p>I tried to use the sorting function for in the viewDidAppear function like this:</p>
  
  <pre><code> var sortedList = myList.sorted { $0.localizedCaseInsensitiveCompare($1) == NSComparisonResult.OrderedAscending }
  </code></pre>
  
  <p>But this gives me an error saying: "Could not find member 'localizedCaseInsensitiveCompare'"</p>
  
  <p>Any suggestions on how to proceed would be appreciated.</p>