gpt4 book ai didi

swift - 识别用户在Parse后端的高分排名

转载 作者:行者123 更新时间:2023-11-30 13:55:10 25 4
gpt4 key购买 nike

我开发了一个简单的 Swift iOS 游戏,高分存储在 Parse 中。保存和检索数据工作正常。我现在想做的是实现“用户排名”功能,该功能将显示用户的高分与其他玩家的排名。实际上,这意味着我需要:

  • Parse 中高分的总数
  • 用户的高分在该列表中的排名

如果 Parse 没有任何查询限制,即使对于像我这样的新手编码人员来说,这也将相对容易实现。然而,它确实如此,我只是不知道如何以一种仍然有效的方式实现它(1)有效,(2)即使有例如 100,000 个高分。

确定当前用户在 Parse 中存储的所有其他高分中的排名的可行方法是什么?我不想使用 countObjects,因为我相信当对象数量变多时它会失败。

最佳答案

您使用的 countObjectsInBackground 是否没有完成 block ?因为这样我相信您可能会遇到异步问题,但使用 countObjectsInBackgroundWithBlock 方法非常简单且非常安全。

func getUserPosition() {
let totalQuery = PFQuery(className: "highScores")
totalQuery.countObjectsInBackgroundWithBlock { (number, error) -> Void in
if error == nil {
//your total number is the number var passed here
let positionQuery = PFQuery(className: "highScores")
positionQuery.whereKey("score", greaterThanOrEqualTo: userHighScore)
positionQuery.countObjectsInBackgroundWithBlock({ (position, error) -> Void in
//your user's position is the position var passed here
})
}
}
}

关于swift - 识别用户在Parse后端的高分排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33724965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com