find(for:withCompletionHandler:)
Creates a new match or finds an existing match that needs a player.
Declaration
class func find(for request: GKMatchRequest, withCompletionHandler completionHandler: @escaping @Sendable (GKTurnBasedMatch?, (any Error)?) -> Void)class func find(for request: GKMatchRequest) async throws -> GKTurnBasedMatchParameters
- request:
The configuration for the turn-based match.
- completionHandler:
The block that GameKit calls when it completes the request.
The block receives the following parameters:
- match
A new or existing match, or
nilif an error occurs.- error
Describes an error if it occurs, or
nilif the operation completes.
Mentioned in
Discussion
When you provide a custom interface for managing matches, use this method to programmatically create or find a turn-based match on behalf of the local player. The local player is always the current participant in the match object GameKit passes to the completion handler. Therefore, implement the completion handler to show the gameplay interface and let the local player take their turn.
To be consistent with older servers and earlier versions of iOS, GameKit sets the minimum number of players specified by the GKMatchRequest object to be equal to the maximum number of players when looking for a match.