Type Method

loadLeaderboards(completionHandler:)

Loads the list of leaderboards from Game Center

Declaration

class func loadLeaderboards(completionHandler: (([GKLeaderboard]?, Error?) -> Void)? = nil)

Parameters

completionHandler

A block that is called when the categories have been retrieved from the server.

The block receives the following parameters:

leaderboards

An array of GKLeaderboard objects that provides the leaderboards for your game. If an error occurred, this value may be non-nil. In this case, the array holds whatever data Game Kit was able to download before the error occurred.

error

If an error occurred, this error object describes the error. If the operation completed successfully, the value is nil.

Discussion

Use this class method to retrieve the list of leaderboards you configured in App Store Connect. Use the properties of each leaderboard object, especially the category and title properties, to learn more about the leaderboard.

Listing 1

Retrieving information about available leaderboards

- (void) loadLeaderboardInfo
{
    [GKLeaderboard loadLeaderboardsWithCompletionHandler:^(NSArray *leaderboards, NSError *error) {
        self.leaderboards = leaderboards;
     }];
}

When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. The completion handler is always called on the main thread.

See Also