loadEntries(for:timeScope:range:completionHandler:)
Returns the scores for the local player and other players for the specified type of player, time period, and ranks.
Declaration
func loadEntries(for playerScope: GKLeaderboard.PlayerScope, timeScope: GKLeaderboard.TimeScope, range: NSRange, completionHandler: @escaping @Sendable (GKLeaderboard.Entry?, [GKLeaderboard.Entry]?, Int, (any Error)?) -> Void)func loadEntries(for playerScope: GKLeaderboard.PlayerScope, timeScope: GKLeaderboard.TimeScope, range: NSRange) async throws -> (GKLeaderboard.Entry?, [GKLeaderboard.Entry], Int)Parameters
- playerScope:
Specifies whether to get scores from friends or all players.
- timeScope:
Specifies the time period for the scores. This parameter is applicable to nonrecurring leaderboards only. For recurring leaderboards, pass Alltime for this parameter.
- range:
Specifies the range of ranks to use for getting the scores. The difference between the minimum rank and maximum rank must not exceed
100. - completionHandler:
A block that GameKit calls when this method completes the request.
The block receives the following parameters:
- localPlayerEntry
The score for the local player, or
nilif the player has no score.- entries
The scores this method loads that match the
playerScope,timeScope, andrangeparameters, including the local player’s score if it exists.- totalPlayerCount
The total number of players whose scores match the
playerScopeandtimeScopeparameters, but not therangeparameter.- error
Describes an error if it occurs, or
nilif the operation completes.
Mentioned in
Discussion
GameKit uses the following algorithm to fetch GKLeaderboard scores:
Begins with the set of all possible scores for the leaderboard.
Discards any scores that don’t match the
playerScopeandtimeScopeproperties.For each player, keeps the best score that player earns and discards the rest.
Sorts the scores from best to worst.
Uses the range property to determine which scores return.