我正在使用 Swift 和 Parse.com 创建一个 iOs 应用程序。不幸的是,我在构建查询时遇到了问题。
我想要什么:我有一个与体育运动员(有进球和传球)的类(class)。我想找回进球最多的球员和传球最多的球员。我的 Parse 类中有两列:目标和传球。
所以,对我来说,我会用
query_goals.limit = 1
query_goals.orderByDescending("goals")
query_passes.limit = 1
query_passes.orderByDescending("passes")
现在我需要连接这两个查询,但我在 swift iOS 文档中没有找到任何相关内容...
有人有想法吗? :)
编辑: 我想在 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
}
在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
关于ios - 解析- swift : Concatenate Queries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32036639/