Swift - 如何以与数组相同的顺序 return 'contained in' 对象?

Swift - how to return 'contained in' objects in same order as array?

我有一个数组,其中包含按特定顺序排列的 objectId 列表。然后我是 运行 一个 PFQuery,带有 "containedIn" 约束。我如何对该查询的结果进行排序,以便返回的对象与其在数组中对应的 objectId 的顺序相同?

谢谢:)

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
        }
    }
}