ios - 如何在扩展中设置只读属性?

标签 ios swift gamekit

我需要在 GKLeaderboard 上模拟 loadScores 请求。 为此我创建了扩展:

extension GKLeaderboard {
    func testLoadScores(completion: @escaping ([GKScore]?, Error?) -> Void) {
        ...
        self.maxRange = 100
    }
}

但是是说

Cannot assign to property: 'maxRange' is a get-only property

那么我该如何覆盖这个属性呢? 链接到属性描述:here

最佳答案

我想问题是 maxRange 属性是在 loadScores(completionHandler:) 完成时自动设置的,你不应该尝试自己设置它

maxRange

This property is invalid until a call to loadScores(completionHandler:) is completed. Afterward, it contains the total number of entries available to return to your game given the filters you applied to the query.

我想你应该使用 range 来获得(过滤)前 N 个分数

range

The range property is ignored if the leaderboard request was initialized using the init(playerIDs:) method. Otherwise, the range property is used to filter which scores are returned to your game. For example, if you specified a range of [1,10], after the search is complete, your game receives the best ten scores. The default range is [1,25]. The minimum index is 1. The maximum length is 100.

或者:如果您想获得所有分数并且分数超过 100 个,那么您似乎应该递归地加载范围越来越大的分数,例如 [1,100]、[101,200] .. . [1101, 1200].. 依此类推,直到您得到一个分数小于 100 的范围。但是实现分页是一个更好的主意,因为可能有太多的乐谱,以至于它们将花费太多时间来加载所有乐谱

关于ios - 如何在扩展中设置只读属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47975541/

相关文章:

ios - 快速从 Url 获取图像名称

ios - 在横向模式下使用 iPad 时,有没有办法在 ios 应用程序中获取滑入式菜单?

ios - com.apple.gamed 在删除游戏时崩溃

iphone - 在游戏中心重新连接玩家

android - Lua Service2Media 移动端

ios - 核心数据后台处理,保存不推送到主上下文

ios - 我的 UICollectionView 不显示图像

arrays - 带有部分的表格 View 搜索栏

ios - 如何隐藏 Xcode 6 中的按钮?

ios - 有没有办法在不发送 "Your Turn"推送通知的情况下更新 GKTurnBasedMatch 中的 matchData?