<!--
{
  "availability" : [
    "iOS: 10.0.0 - 12.0.0",
    "iPadOS: 10.0.0 - 12.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.12.0 - 10.14.0",
    "tvOS: 10.0.0 - 12.0.0",
    "visionOS: 1.0.0 - 1.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "GameKit",
  "identifier" : "/documentation/GameKit/GKGameSession/createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "GameKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKGameSession(cm)createSessionInContainer:withTitle:maxConnectedPlayers:completionHandler:"
  },
  "title" : "createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:)"
}
-->

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

Creates a new game session inside of an iCloud container.

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

## 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.

- gameSession: A `GKGameSession` object containing information about the newly created game session.
- error: If an error occurred, this parameter holds an error object that explains the error. Otherwise, the value of this parameter is nil. See `GameKit Constants` for a list of error codes specific to GameKit.

## 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:)`](/documentation/GameKit/GKGameSession/remove(withIdentifier:completionHandler:)). See [iCloud Design Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/iCloudDesignGuide/Chapters/Introduction.html#//apple_ref/doc/uid/TP40012094) for more information on incorporating iCloud in your app.

---

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)