Type Method


Loads information from Game Center about a list of players.


class func loadPlayers(forIdentifiers identifiers: [String], withCompletionHandler completionHandler: (([GKPlayer]?, Error?) -> Void)? = nil)



An array of NSString objects, each a unique identifier for a Game Center player.


A block to be called when the player data is retrieved from Game Center.

The block receives the following parameters:


An array of GKPlayer objects, one per identifier. If an error occurred, this may be non-nil. In that case, the array holds whatever data Game Kit was able to retrieve for the requested players.


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


Listing 1 shows an example of how to load the GKPlayer objects associated with player identifiers.

Listing 1

Retrieving player details

- (void) loadPlayerData: (NSArray *) identifiers
    [GKPlayer loadPlayersForIdentifiers:identifiers withCompletionHandler:^(NSArray *players, NSError *error) {
        if (error != nil)
            // Handle the error.
        if (players != nil)
            // Process the array of GKPlayer objects.

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