Reputation: 874
I want to sort a NSManagedObject fetched from CoreData. I already have NSSortDescriptor when i fetch results. However, results come from two different fetch requests. I combine then again in a array of NSManagedObjet. I would like to sort that array in ascending order.
There is
NAManagedObject.sorted(by: (NSManagedObject, NSManagedObject) throws -> bool)
Not sure how to use it.
Upvotes: 0
Views: 356
Reputation: 9351
Assuming your array is called results, it might be something like this:
let sortedArray = results.sorted { (first, second) -> Bool in
return first.value > value.value
}
...where 'value' is the value you want to sort by. This would give a descending sort - you basically want to return true if 'first' should appear before 'second' in the resulting list.
Upvotes: 1