---
title: "createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:)"
framework: gamekit
role: symbol
role_heading: Type Method
path: "gamekit/gkgamesession/createsession(incontainer:withtitle:maxconnectedplayers:completionhandler:)"
---

# createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:)

Creates a new game session inside of an iCloud container.

## Declaration

```swift
class func createSession(inContainer containerName: String?, withTitle title: String, maxConnectedPlayers maxPlayers: Int, completionHandler: @escaping @Sendable (GKGameSession?, (any Error)?) -> Void)
```

```swift
class func createSession(inContainer containerName: String?, withTitle title: String, maxConnectedPlayers maxPlayers: Int) async throws -> GKGameSession
```

## Parameters

- `containerName`: A String value representing the iCloud container for the game session.
- `title`: A String value representing the title of the game session.
- `maxPlayers`: An Integer value indicating the maximum number of players allowed in the game session.
- `completionHandler`: A block that is called after a new game session has been created.

## Discussion

Discussion The container name must be a valid iCloud container associated with your app. After a user has finished a game and is done with a game session, remove the created game session from iCloud using remove(withIdentifier:completionHandler:). See iCloud Design Guide for more information on incorporating iCloud in your app.

## See Also

### Creating and Loading Game Sessions

- [load(withIdentifier:completionHandler:)](gamekit/gkgamesession/load(withidentifier:completionhandler:).md)
- [loadSessions(inContainer:completionHandler:)](gamekit/gkgamesession/loadsessions(incontainer:completionhandler:).md)
- [remove(withIdentifier:completionHandler:)](gamekit/gkgamesession/remove(withidentifier:completionhandler:).md)
