PFQuery from an array in order SWIFT -
i want use parse pfquery query array of objects, want outcome in order have put in, example:
var age = [26, 28, 30, 20] var agequery = pfuser.query() agequery.wherekey("age", containedin: age) let finalresult = agequery.findobjects() println(finalresult) // equal search in order have put them in, first result should 26, 28 etc.
is there of searching in order put in?
thanks
i don't believe so. documentation doesn't promise order of results.
your best option sort results once have received them. consider using sortedarrayusingcomparator
, each object you're comparing find index in source array , use indexes decide resulting nscomparisonresult
.
in swift seems can shortcut little, along lines of:
var sortedresult = sorted(finalresult) { (obj1, obj2) in let p1 = obj1 person let p2 = obj2 person let index1 = find(age, p1.age)! let index2 = find(age, p2.age)! return index1 < index2 }
Comments
Post a Comment