loadLeaderboards(completionHandler:)
Loads a list of leaderboards from Game Center.
Declaration
class func loadLeaderboards(completionHandler: (@Sendable ([GKLeaderboard]?, (any Error)?) -> Void)? = nil)class func loadLeaderboards() async throws -> [GKLeaderboard]Parameters
- completionHandler:
A block to call when loading the leaderboards.
The block receives the following parameters:
- leaderboards
An array of
GKLeaderboardobjects that provides the leaderboards for your game. If an error occurs, this value may be non-nil. In this case, the array holds whatever data GameKit downloads before the error occurs.- error
If an error occurs, this error object describes the error. If the operation completes successfully, the value is
nil.
Discussion
Use this class method to retrieve the list of leaderboards you configure in App Store Connect. Use the properties of each leaderboard object, especially the category and title properties, to learn more about the leaderboard.
- (void) loadLeaderboardInfo
{
[GKLeaderboard loadLeaderboardsWithCompletionHandler:^(NSArray *leaderboards, NSError *error) {
self.leaderboards = leaderboards;
}];
}When you call this method, it creates a new background task to handle the request. The method then returns control to your game. When the task is complete, GameKit calls your completion handler on the main thread.