如何根据数组顺序使NSSortDeScriptor进行排序?
我有一个对象ID数组,并且数组具有正确的顺序。
let objectsIDs = [504, 316, 195, ...]
而且我正在使用此nsfetchedResultSconTroller
使用nspredicate
:
NSPredicate(format: "%K IN %@", #keyPath(object.id), objectsIDs)
nsfetchedResultscontroller
需要nssortdescriptor
,我无法使用 contect 代码>或ID
属性对象进行分类。
如何获得nssortDescriptor
根据objectsids
数组顺序对对象进行排序? objectsids
数组始终具有正确的顺序,nssortDescriptor
必须取决于其顺序。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。您要做的是 cosort 数组,即按照另一个数组的顺序对其进行排序。 NSSORTDESCRIPTOR不这样做。 您必须这样做。合作社是一个经过充分讨论的问题。
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.