GKLeaderboard
A leaderboard for a game that Game Center stores.
Declaration
class GKLeaderboardMentioned in
Overview
Leaderboards allow players to compare their scores against other players in your game. You configure a classic or recurring leaderboard in App Store Connect and then access the localized information for a leaderboard in your code using GKLeaderboard objects.
A classic leaderboard is persistent, that is, the scores never reset unless you delete the leaderboard. A recurring leaderboard contains scores for a period of time useful for competitions and encouraging players to try for higher scores. You configure the duration, frequency, and delay between occurrences that Game Center uses to automatically restart the leaderboard in App Store Connect.
In your code, you use the identifier you set for the leaderboard in App Store Connect to submit scores or load leaderboards. Use the submitScore(_:context:player:leaderboardIDs:completionHandler:) class method to submit a score to one or more leaderboards. Alternatively, load a recurring leaderboard using the loadLeaderboards(IDs:completionHandler:) class method and then submit a score using the submitScore(_:context:player:completionHandler:) method. To learn more about recurring leaderboards, see Creating recurring leaderboards.
To retrieve information about all leaderboards in your game, use the loadLeaderboards(IDs:completionHandler:) class method. To fetch the scores for a leaderboard, use the loadEntries(for:timeScope:range:completionHandler:) or loadEntries(for:timeScope:completionHandler:) method. Use the parameters of these methods to filter the scores to the player’s friends, a rank, and time period when the score occurs.
You must create leaderboard objects using one of the load methods above. If the request is successful, GameKit passes corresponding GKLeaderboard objects to the handler. GameKit doesn’t load the images you add to App Store Connect when it loads the leaderboards. Use the loadImage(completionHandler:) method to get the image for a leaderboard.
Topics
Accessing Identifier and Type Properties
Accessing Recurring Leaderboard Properties
Loading Leaderboards
Loading Leaderboard Images
Submitting Scores
submitScore(_:context:player:leaderboardIDs:completionHandler:)submitScore(_:context:player:completionHandler:)
Loading Scores
loadEntries(for:timeScope:range:completionHandler:)loadEntries(for:timeScope:completionHandler:)GKLeaderboard.PlayerScopeGKLeaderboard.TimeScopeGKLeaderboard.Entry