How can I retrieve all scores for a GKLeaderboard? (I'm making my own leaderboard graphics). I'd need to know the number of scores in a certain leaderboard, but there seems to be no way of polling GC for that kind of information?
-
apple document have this kind of info, please see this section [link](http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html#//apple_ref/doc/uid/TP40008304-CH6-SW14) – Scar Sep 18 '12 at 05:59
-
1That looks exactly like the link that I posted in my question? Exactly where is the documentation on the amount of scores in a leaderboard? Also I think you should include that info in an answer... – Jonny Sep 18 '12 at 06:08
4 Answers
I'm getting the feeling the answer is the maxRange property of GKLeaderboard. The docs:
This property is invalid until a call to loadScoresWithCompletionHandler: is completed. Afterward, it contains the total number of entries available to return to your game given the filters you applied to the query.
So this would be the number of rows in a leaderboard table view.

- 15,955
- 18
- 111
- 232
-
-
Don't remember now but try checking the `maxRange` property of the `GKLeaderboard` object in the `loadScoresWithCompletionHandler` handler. – Jonny Oct 10 '13 at 08:00
In the apple document, there is a section called Retrieving Leaderboard Scores, they use an example of how to retrive a top 10 score:
- (void) retrieveTopTenScores
{
GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil)
{
leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardRequest.range = NSMakeRange(1,10);
[leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
if (error != nil)
{
// handle the error.
}
if (scores != nil)
{
// process the score information.
}
}];
}
}
We can edit the range of the leaderboardRequest
, to retrive more scores, apple said in there document:
range
The numerical score rankings to return from the search.
@property(nonatomic, assign) NSRange range
Discussion The range
property is ignored if the leaderboard request was initialized using the initWithPlayerIDs: 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 top ten scores. The default range is [1,25].
The minimum index is 1. The maximum length is 100.
-
Sorry what I need to know is how to get all scores, and the straight forward way of doing that would be to know the amount of scores in a leaderboard. AFAIK there is no way of retrieving the last index by a NSRange. like NSRangeMake(-1, 1) or something I guess wouldn't work. – Jonny Sep 18 '12 at 06:57
In order to get all the scores, you need to request them in chunks using the range that Scar details. Typically in games you display a subset of say 100, and give the user the option to see a lower subset or a higher subset.

- 188
- 2
- 6
I see that this question is over 10 years old now, so interfaces will have changed quite a lot in that time. I was interested in loading a set of scores from a leaderboard in iOS 14+ with the hope of being able to display the scores around the local player's own score, like how GKGameCenterViewController
does it. There are two reasons for wanting to do this:
- As a workaround for the dark leaderboard issue reported in GKGameCenterViewController showing as black text on dark background on iPads running iPadOS 16
- To allow the context for a score to be used to enrich the information displayed.
After examining the (non-deprecated) functions of GKLeaderboard
, I came to the following conclusions:
- The function
loadEntries(for:timeScope:range:completionHandler:)
would seem to be the best function available. - The completion handler receives the totalPlayerCount as third parameter. This provides an answer to the original 10-year-old question of how to get the number of scores in a certain leaderboard!
- But... the range only allows scores in the top 100 to be fetched (min value 1, max value 100).
I tried supplying a range which broke the min/max rules and it caused a crash.
There is another loadEntries
function which lets you fetch scores for other players that you can identify. This could be used to fetch the scores of friends, but otherwise it doesn't help much.
So for iOS14+, the bottom line is: although it is at least possible to determine how many scores are in a leaderboard, it seems you can only fetch the local player's own score and scores in the top 100.

- 1,546
- 2
- 3
- 10