-1
我有一個數組,其中包含一個非常特定的順序objectId列表。然後我運行一個PFQuery,帶有「containedIn」約束。如何排序此查詢的結果,以便返回的對象與它們在數組中對應的objectId的順序相同?Swift - 如何以與數組相同的順序返回'包含在'對象中?
謝謝:)
我有一個數組,其中包含一個非常特定的順序objectId列表。然後我運行一個PFQuery,帶有「containedIn」約束。如何排序此查詢的結果,以便返回的對象與它們在數組中對應的objectId的順序相同?Swift - 如何以與數組相同的順序返回'包含在'對象中?
謝謝:)
PFQueries只能按某些列中的值排序。因此,您可以使用「orderByDesecending」或「orderByAscending」(例如日期或按名稱的字母順序),但不存在「orderToMatchTheOrderOfMyArray」。
我會建議只是手動排序它們。它不應該很難。我不是一個快速的開發者,但這裏是僞代碼:
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
}
}
}
你是一個英雄。我真的是在智慧的結尾,這非常聰明。我深深地感謝你 –