The GKTurnBasedMatchmakerViewController class displays a user interface that allows players to manage the turn-based matches that they are participating in.


To show a turn-based matching user interface, first allocate and initialize a GKMatchRequest object that describes the desired match. Then, use the match request to initialize a new GKTurnBasedMatchmakerViewController object. Set the view controller’s delegate, present the view controller, and wait for the delegate to be called. The view controller’s delegate is notified when the matchmaking process is completed or canceled. 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. In macOS, you use the GKDialogController class to present and dismiss the view controller. Listing 1 shows a typical implementation.

Listing 1

Displaying the standard interface to join a turn-based match

- (IBAction)joinChessMatch: (id) sender
    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.minPlayers = 2;
    request.maxPlayers = 2;
    GKTurnBasedMatchmakerViewController *mmvc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
    mmvc.turnBasedMatchmakerDelegate = self;
    [self presentViewController:mmvc animated:YES completion:nil];


Displaying a UI For Turn-Based Matches

init(matchRequest: GKMatchRequest)

Initializes a new matchmaker view controller.

var showExistingMatches: Bool

A Boolean value that determines whether the view controller shows existing matches.