iOS Developer Library — Prerelease

Developer

GKLeaderboardSet Class Reference

Options
Deployment Target:

On This Page
Language:

GKLeaderboardSet

Add leaderboard sets to your app and organize your leaderboards into logical and coherent groups. Once you incorporate leaderboard sets into your app, you must put all of your leaderboards into a set. Individual leaderboards can be put into multiple leaderboard sets and given different display names in each set.

A GKLeaderboardSet object is used to read data from a leaderboard set stored on Game Center. Your game uses GKLeaderboardSet objects when it wants to retrieve localized information about a specific leaderboard set or to retrieve scores from a leaderboard set. Typically, you do this when you want the data needed to implement your own custom leaderboard set user interface.

During the development process, you create the leaderboard sets for your game on iTunes Connect.

To retrieve information about the available leaderboards for the current set, use the loadLeaderboardsWithCompletionHandler: class method.

To retrieve information about the available leaderboard sets, use the loadLeaderboardSetsWithCompletionHandler: class method.

To retrieve information about the image associated with a leaderboard set, use the loadImageWithCompletionHandler: class method.

  • Load the image associated with the leaderboard set.

    Declaration

    Swift

    func loadImageWithCompletionHandler(_ completionHandler: ((UIImage?, NSError?) -> Void)?)

    Objective-C

    - (void)loadImageWithCompletionHandler:(void (^ _Nullable)(UIImage * _Nullable image, NSError * _Nullable error))completionHandler

    Parameters

    completionHandler

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

    The block receives the following parameters:

    image

    The image associated with the leaderboard set. If an error occurred, this value will 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

    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.

    Availability

    Available in iOS 7.0 and later.

  • Load all of the leaderboard sets for the current game.

    Declaration

    Swift

    class func loadLeaderboardSetsWithCompletionHandler(_ completionHandler: (([GKLeaderboardSet]?, NSError?) -> Void)?)

    Objective-C

    + (void)loadLeaderboardSetsWithCompletionHandler:(void (^ _Nullable)(NSArray<GKLeaderboardSet *> * _Nullable leaderboardSets, NSError * _Nullable error))completionHandler

    Parameters

    completionHandler

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

    The block receives the following parameters:

    leaderboardSets

    An array of GKLeaderboardSet objects that provides the leaderboard sets 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

    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.

    Availability

    Available in iOS 7.0 and later.

  • Load all of the leaderboards for the current leaderboard set.

    Declaration

    Swift

    func loadLeaderboardsWithCompletionHandler(_ completionHandler: (([GKLeaderboard]?, NSError?) -> Void)?)

    Objective-C

    - (void)loadLeaderboardsWithCompletionHandler:(void (^ _Nullable)(NSArray<GKLeaderboard *> * _Nullable leaderboards, NSError * _Nullable error))completionHandler

    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

    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.

    Availability

    Available in iOS 7.0 and later.

  • Localized title for the leaderboard set. (read-only)

    Declaration

    Swift

    var title: String { get }

    Objective-C

    @property(readonly, copy, nonatomic) NSString * _Nonnull title

    Availability

    Available in iOS 7.0 and later.

  • The identifier for the leaderboard set.

    Declaration

    Swift

    var identifier: String?

    Objective-C

    @property(copy, nonatomic) NSString * _Nullable identifier

    Availability

    Available in iOS 7.0 and later.

  • Identifies the group that the leaderboard set belongs to. (read-only)

    Declaration

    Swift

    var groupIdentifier: String? { get }

    Objective-C

    @property(nonatomic, readonly, retain) NSString * _Nullable groupIdentifier

    Discussion

    This is set when the leaderboard set is part of a game group. It gets set when loadLeaderboardSetsWithCompletionHandler: is called on leaderboards that support game groups.

    Availability

    Available in iOS 7.0 and later.