I have an array of object IDs and the array has the correct order.
let objectsIDs = [504, 316, 195, ...]
And I am using NSFetchedResultsController with this NSPredicate:
NSPredicate(format: "%K IN %@", #keyPath(object.id), objectsIDs)
NSFetchedResultsController requires NSSortDescriptor and I cannot use createdAt or id property to sort the objects.
How can I get NSSortDescriptor to sort the objects based on the objectsIDs array order? The objectsIDs array always have the correct order and NSSortDescriptor must depend on its order.
You can't. What you're trying to do is cosort the array, ie sort it according to the order of another array. NSSortDescriptor doesn't do that. You have to do it. Cosorting is a well discussed problem.