1

I am returning some data from a fetch request, the field is stored as a String. What I want to do is sort the results so that the numbers are in order

let sortDescriptor = NSSortDescriptor(key: "number", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]

The order I'm wanting is 1,2,3,100, 200, 1544, White The ones which are actual strings doesn't matter if its at the start or end ( End is preferred but not needed)

1, 100, 1544, 2, 3, White

Ceri Turner
  • 830
  • 2
  • 12
  • 36

1 Answers1

2
var sortDescriptor = NSSortDescriptor(key: "title", ascending: true,
            selector: #selector(NSString.localizedStandardCompare))
fetchRequest.sortDescriptors = [sortDescriptor]
Rahul Dasgupta
  • 894
  • 6
  • 18