【发布时间】:2015-08-25 19:12:34
【问题描述】:
我有一个数组,其中包含一个非常特定顺序的 objectId 列表。然后我运行一个带有“containedIn”约束的 PFQuery。如何对该查询的结果进行排序,以便返回的对象与其对应的 objectId 在数组中的顺序相同?
谢谢:)
【问题讨论】:
标签: ios arrays swift parse-platform pfquery
我有一个数组,其中包含一个非常特定顺序的 objectId 列表。然后我运行一个带有“containedIn”约束的 PFQuery。如何对该查询的结果进行排序,以便返回的对象与其对应的 objectId 在数组中的顺序相同?
谢谢:)
【问题讨论】:
标签: ios arrays swift parse-platform pfquery
PFQueries 只能按某些列中的值排序。所以你可以使用带有键的“orderByDesecending”或“orderByAscending”(例如日期,或按名称的字母顺序),但没有“orderToMatchTheOrderOfMyArray”。
我建议只手动对它们进行排序。应该不难。我不是 swift 开发人员,但这里是伪代码:
sortedObjects = [] //start with empty array
for each ObjectId in MyListOfObjectIds { //loop through your ordered objectIds
for each object in MyQueriedObjects { //loop through the objects you got from the query
if (ObjectId == object.objectId) { //if you've found the correct object
sortedObjects.addObject(object); //add it to the list
break; //move on to the next ordered objectId
}
}
}
【讨论】: