<!--
{
  "documentType" : "article",
  "framework" : "GameKit",
  "identifier" : "/documentation/GameKit/letting-players-join-matches-using-party-codes",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Letting players join matches using party codes"
}
-->

# Letting players join matches using party codes

Add a rule that lets players invite players and join matches using a shared party code.

## Discussion

You can let players start a party or group game with other players who they share a party code with. You provide an interface in your game for creating a party code, and then starting and joining matches using that party code. Then use matchmaking rules to ensure that Game Center only matches players with the same party code.

### Create a custom party code interface

In your code, implement a party code feature that:

- Generates a unique party code for the local player
- Initiates a match request from the local player using the party code
- Shares the party code with their friends and others who they want to invite
- Submits match requests from other players who receive a party code

The party code can be any combination of letters, numbers, or other characters that forms a unique identifier.

To share the party code, you can use in-game chat or data exchange in an existing match, or let the player copy the code and share outside of your game.

To submit match requests without presenting an interface using automatch, see [Let Game Center match the player with others](/documentation/GameKit/finding-multiple-players-for-a-game#Let-Game-Center-match-the-player-with-others).

### Add a party code matchmaking rule

Then create a compatible rule that finds players who have the same party code.

In a compatible rule, the `requests` array in the expression contains two match requests to compare. Write an expression that returns <doc://com.apple.documentation/documentation/Swift/true> if the party code for the two requests is the same.

```json
requests[0].properties.partyCode == requests[1].properties.partyCode
```

Create the party code rule using the <doc://com.apple.documentation/documentation/AppStoreConnectAPI/POST-v1-gameCenterMatchmakingRuleSets> endpoint. In the `attributes` field, set the rule’s `type` field to `COMPATIBLE` and pass the party code expression. Set the `description` and `referenceName` fields to strings that make sense for your game. In the `relationships` field, pass the `id` for the rule set in the <doc://com.apple.documentation/documentation/AppStoreConnectAPI/GameCenterMatchmakingQueueCreateRequest/Data-data.dictionary/Relationships-data.dictionary/RuleSet-data.dictionary/Data-data.dictionary> object.

```json
POST /v1/gameCenterMatchmakingRules
{
    "data": {
        "type": "gameCenterMatchmakingRules",
        "attributes": {
            "type": "COMPATIBLE",
            "description": "Check whether the players have the same party code.",
            "referenceName": "PartyCode",
            "expression": "requests[0].properties.partyCode == requests[1].properties.partyCode"
        },
        "relationships": {
            "ruleSet": {
                "data": {
                    "type": "gameCenterMatchmakingRuleSets",
                    "id": "9e313753-2b8a-4762-b941-26f30c4184d2"
                }
            }
        }
    }
}
```

To create a rule set, see [Create rule sets that contain the matchmaking rules](/documentation/GameKit/finding-players-using-matchmaking-rules#Create-rule-sets-that-contain-the-matchmaking-rules).

### Create match requests using party codes

In your code, create a match request that initiates or joins a party by adding a `partyCode` key-value pair to the request’s `GKMatchRequest` [`properties`](/documentation/GameKit/GKMatchRequest/properties) dictionary.

```swift
// Create a match request.
let request = GKMatchRequest()

// Set the matchmaking rules queue name.
request.queueName = "com.example.mygame.PartyCodeQueue"

// Set properties to the game-specific keys you use in the rules.
request.properties = [ "partyCode": partyCode]
```

Game Center finds all compatible players in the queue that have the same party code.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)