[英]Parse - Swift : Concatenate Queries
I'm creating an iOs app with Swift and Parse.com. 我正在使用Swift和Parse.com创建一个iOs应用程序。 Unfortunately, i've a problem when I build my query.
不幸的是,我在建立查询时遇到问题。
What I want : I have a class with sport's players (with goals and passes). 我想要的是:我和体育运动员一起上课(有进球和传球)。 I would like to retrieve the player with the most goals and the player with the most passes.
我想找回进球最多的球员和传球最多的球员。 I have two columns in my Parse class : goals and passes.
我的Parse类中有两列:目标和通过。
So, for me, I would use 所以,对我来说,我会用
query_goals.limit = 1
query_goals.orderByDescending("goals")
query_passes.limit = 1
query_passes.orderByDescending("passes")
and now I need to concat the two queries but I didn't find anything for that in swift iOS documentation... 现在我需要对两个查询进行合并,但是在快速的iOS文档中没有找到任何关于此的内容...
Does anyone have an idea please ? 请问有人有主意吗? :)
:)
EDIT : I want to print the best scorer and passer in collectionView cells : 编辑:我想在collectionView单元格中打印最好的得分手和传球手:
override func queryForCollection() -> PFQuery {
let query = PFQuery(className: "liste_joueurs")
query.limit = 1
query.orderByDescending("goals")
let query_passes = PFQuery(className: "liste_joueurs")
query_passes.limit = 1
query.orderByDescending("passes")
let final_query = query + query_passes //Swift Concat to illustrate my purpose
return final_query
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFCollectionViewCell? {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("statsCell", forIndexPath: indexPath) as! StatsViewCell
// First cell for best scorer
// Second cell for best passer
return cell
}
In the final_query , 在final_query中 ,
let query = PFQuery(className : "SportsPlayers") // Im assuming your classname change it as needed
// for highest scorer
query.orderByDescending("goals")
query.limit = 1
// for highest passes
query.orderByDescending("passes")
query.limit = 1
Ok I just found a solution. 好吧,我刚刚找到了解决方案。 I don't need to use queryForCollection and concatenate queries but create a query and use findObjectsInBackgroundWithBlock function in every cell of my collectionView.
我不需要使用queryForCollection和连接查询,而是创建一个查询并在collectionView的每个单元格中使用findObjectsInBackgroundWithBlock函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.