Contents

setDefault(_:withCompletionHandler:)

Sets the default leaderboard for the local player.

Declaration

class func setDefault(_ leaderboardIdentifier: String?, withCompletionHandler completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
class func setDefault(_ leaderboardIdentifier: String?) async throws

Parameters

  • leaderboardIdentifier:

    The named leaderboard that is the new default leaderboard for the local player.

  • completionHandler:

    A block to call after retrieving scores from the server.

    The block receives the following parameter:

    error

    If an error occurs, this error object describes the error. If the operation completes successfully, the value is nil.

Discussion

GameKit uses the default leaderboard whenever your game uses a GKScore object to report a score to Game Center without explicitly setting the score object’s category property. You normally set the default leaderboard in App Store Connect. However, your game can use this class method to override the default leaderboard that appears for the local player. Game Center stores this information for each player.

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 completes, GameKit calls your completion handler on the main thread.

If an error occurs and it’s a network error, periodically resend the request until it completes.

See Also

Deprecated methods