Mac Developer Library

Developer

GameKit Framework Reference GKLeaderboardViewController Class Reference

Options
Deployment Target:

On This Page
Language:

GKLeaderboardViewController

Conforms To


Import Statement


Swift

import GameKit

Objective-C

@import GameKit;

Availability


Available in OS X v10.8 and later.

The GKLeaderboardViewController class provides a standard user interface that displays leaderboard scores to the player. If the GKGameCenterViewController class is available, you should use it instead.

To show a leaderboard screen, initialize a new GKLeaderboardViewController object and set the delegate. Optionally, you can configure the view controller to display specific data to the player. Then, present the new view controller and wait for the delegate to be called. Once the delegate is called, dismiss the view controller.

On iOS, you present and dismiss the view controller from another view controller in your game, using the methods provided by the UIViewController class. On OS X, you use the GKDialogController class to present and dismiss the view controller.

Your game should pause other activities before presenting the leaderboard.

Subclassing Notes

The GKLeaderboardViewController class is not intended to be subclassed.

  • category category Property

    The named leaderboard that is displayed by the view controller.

    Declaration

    Swift

    var category: String!

    Objective-C

    @property(copy, atomic) NSString *category

    Discussion

    The category property must either be nil or it must match a leaderboard identifier for a leaderboard you defined in iTunes Connect. If nil, the view displays scores for the default leaderboard. Default is nil.

    When the view controller is presented, the initial leaderboard shown is based on the value of this property. If the player changes which leaderboard they are viewing, the category property is automatically updated. For example, you can read the category property after the screen is dismissed, and set that value the next time you initialize a new leaderboard view controller.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • The view controller’s delegate.

    Declaration

    Swift

    unowned(unsafe) var leaderboardDelegate: GKLeaderboardViewControllerDelegate!

    Objective-C

    @property(assign, atomic) id< GKLeaderboardViewControllerDelegate > leaderboardDelegate

    Discussion

    Before displaying the leaderboard, you must set a delegate.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.

  • timeScope timeScope Property

    A time filter used to restrict which scores are displayed to the player.

    Declaration

    Swift

    var timeScope: GKLeaderboardTimeScope

    Objective-C

    @property(assign, atomic) GKLeaderboardTimeScope timeScope

    Discussion

    This property determines which tab view is displayed to the player. The default value is GKLeaderboardTimeScopeAllTime, which shows the best score each player has earned. For more information on time scopes, see GKLeaderboard Class Reference.

    If the player changes which tab they view, the timeScope property is automatically updated. For example, you can read the timeScope property after the view controller is dismissed, and set that value the next time you initialize a new leaderboard view controller.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in OS X v10.8 and later.