GKTurnBasedMatch
An object that encapsulates the match data for games where players take turns.
Declaration
class GKTurnBasedMatchMentioned in
Overview
A GKTurnBasedMatch object represents a match in a turn-based game that Game Center stores and forwards to participants in the match. In a turn-based game, participants take turns to advance gameplay until they reach an outcome. You end the match when all participants reach an outcome or they can no longer continue.
A turn-based match object contains the status of the match, list of participants, the participant whose turn it is, a message about the last turn, and your game-specific data. You can get more details about the participants through the GKTurnBasedParticipant objects in the participants property.
You don’t create turn-based match objects directly. When a match event occurs, GameKit passes the match object to listeners that conform to the GKTurnBasedEventListener protocol. Retain the match object or its match ID in the protocol methods, so you can get the latest match data later during gameplay.
Using the match object passed to GKTurnBasedEventListener protocol methods, you can perform these actions on behalf of the local player:
Save game data
End a turn
Forfeit a match
End a match
Send a reminder to the participant whose turn it is
Exchange data between participants
Remove a completed match from Game Center
When you end a turn, forfeit a match, or end a match, you update the match data and if gameplay can continue, choose the next participant. If you end a match, you set the individual participant outcomes as well.
If you present a GKTurnBasedMatchmakerViewController object for players to manage their turn-based matches, the player can start a match, accept an invitation, open an existing match, and forfeit a match.
Subclassing Notes
Don’t subclass the GKTurnBasedMatch class.
Topics
Creating a Match
find(for:withCompletionHandler:)acceptInvite(completionHandler:)declineInvite(completionHandler:)rematch(completionHandler:)
Retrieving Match Details
matchIDcreationDateparticipantscurrentParticipantstatusGKTurnBasedMatch.StatusmatchDatamatchDataMaximumSizeloadMatchData(completionHandler:)
Ending Turns and Saving Data
endTurn(withNextParticipants:turnTimeout:match:completionHandler:)saveCurrentTurn(withMatch:completionHandler:)Turn Timeouts
Forfeiting a Match
participantQuitInTurn(with:nextParticipants:turnTimeout:match:completionHandler:)participantQuitOutOfTurn(with:withCompletionHandler:)GKTurnBasedMatch.Outcome
Ending a Match
endMatchInTurn(withMatch:completionHandler:)endMatchInTurn(withMatch:leaderboardScores:achievements:completionHandler:)
Sending Messages Between Participants
messagesetLocalizableMessageWithKey(_:arguments:)sendReminder(to:localizableMessageKey:arguments:completionHandler:)
Exchanging Data Between Participants
sendExchange(to:data:localizableMessageKey:arguments:timeout:completionHandler:)Exchange TimeoutsexchangeDataMaximumSizeexchangeMaxInitiatedExchangesPerPlayeractiveExchangescompletedExchangesexchangessaveMergedMatch(_:withResolvedExchanges:completionHandler:)
Loading Existing Matches
Deleting a Match from Game Center
Deprecated Methods
See Also
Turn-based games
Creating turn-based gamesStarting turn-based matches and passing turns between playersSending messages to players in turn-based gamesExchanging data between players in turn-based gamesGKTurnBasedMatchmakerViewControllerGKTurnBasedParticipantGKTurnBasedEventListenerGKTurnBasedExchangeGKTurnBasedExchangeReplyGKGameCenterBadgingDisabled