DXLeaderboardClient

This class is responsible for making requests to the DX leaderboard API.

public final class DXLeaderboardClient

While DX buckets allow your app to store private data for a single user, or share data between multiple users, leaderboards allow you to create and share scores between all users of your app. Leaderboard scores will be returned sorted, allowing you to create high score leaderboards visible to all users of your app. You can also create leaderboard entries with a "category" tag, allowing you to create multiple distinct leaderboards for your app.

You will need to enable the "Leaderboard" scope for your app in the developer dashboard before using the leaderboard API.

Properties

public static let shared: DXLeaderboardClient

Singleton instance of DXLeaderboardClient. You will access all the available DXLeaderboardClient methods through this instance.

Methods

getLeaderboard

public func getLeaderboard(
    _ page: Int? = nil, 
    _ limit: Int? = nil, 
    forCategories categories: [String], 
    _ completion: @escaping (_ error: Error?, _ leaderboardEntries: [DXLeaderboardEntry]?) -> Void
) -> Void

Get all leaderboard entries for your app or filter out leaderboard entries by supplying one or more category tags. Supports pagination through the page and limit parameters.

Parameter

Type

Description

page

Int?

At what page to return leaderboard entries, where page length is determined by limit.

limit

Int?

The maximum number of leaderboard entries to return.

forCategories

[String]

Filter leaderboard entries by specifying what entries to return based on their category tags. An empty array will return all entries.

completion

(Error?, [DXLeaderboardEntry]?) -> Void

The closure invoked when the request finishes.

error

Error?

The error returned for an unsuccessful request.

leaderboardEntries

[DXLeaderboardEntry]?

The leaderboard entries returned for a successful request.

updateLeaderboard

public func updateLeaderboard(
    _ score: Double, 
    forCategories categories: [String], 
    _ completion: ((_ error: Error?, _ leaderboardEntry: DXLeaderboardEntry?) -> Void)?
) -> Void

Add a leaderboard entry. Entries are simply represented by a score (Double) and can be created with zero or more category tags. If a leaderboard entry already exists with the same categories, an upsert will be performed, rather than creating a new entry.

Parameter

Type

Description

score

Double

The score being added.

forCategories

[String]

List of categories to tag the leaderboard with.

completion

((Error?, DXLeaderboardEntry?) -> Void)?

The closure invoked after the request finishes.

error

Error?

The error returned for an unsuccessful request.

leaderboardEntry

DXLeaderboardEntry?

The newly created leaderboard entry returned for a successful request.

Last updated