---
title: GKGameSession
framework: gamekit
role: symbol
role_heading: Class
path: gamekit/gkgamesession
---

# GKGameSession

A game session you can use to save game data, invite other players, and create turn-based and real-time game apps.

## Declaration

```swift
class GKGameSession
```

## Overview

Overview Use a GKGameSession object to play turn-based and real-time games in iCloud. Every instance of a game session resides inside of an iCloud container. You can create multiple sessions for a single app, allowing players to play several games at once. All of the information for a game session is saved in the owner’s iCloud. Each session can contain a maximum of 100 players. Inside of a session, up to 16 of those players can be connected to each other in real-time. The 16 connected players can be selected from any of the 100 players in the session. You can change a connected player with another player in the session at any time. After a game session is created, you can save game data in iCloud. Each game session can save a maximum of 512KB data. This prevents games from using a large about of space in a user’s iCloud account. This data can be loaded, edited, and saved by anyone in the game session, providing your app provides this behavior. You must ensure that you delete a game session from a user’s iCloud after a game is over, otherwise the session will stay in the user’s iCloud forever. Game sessions are not automatically removed after a set amount of time. They can only be actively removed.

## Topics

### Creating and Loading Game Sessions

- [createSession(inContainer:withTitle:maxConnectedPlayers:completionHandler:)](gamekit/gkgamesession/createsession(incontainer:withtitle:maxconnectedplayers:completionhandler:).md)
- [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)

### Accessing Information About a Game Session

- [identifier](gamekit/gkgamesession/identifier.md)
- [lastModifiedDate](gamekit/gkgamesession/lastmodifieddate.md)
- [lastModifiedPlayer](gamekit/gkgamesession/lastmodifiedplayer.md)
- [maxNumberOfConnectedPlayers](gamekit/gkgamesession/maxnumberofconnectedplayers.md)
- [owner](gamekit/gkgamesession/owner.md)
- [players](gamekit/gkgamesession/players.md)
- [title](gamekit/gkgamesession/title.md)

### Inviting Players to a Game Session

- [getShareURL(completionHandler:)](gamekit/gkgamesession/getshareurl(completionhandler:).md)

### Saving and Loading Data

- [loadData(completionHandler:)](gamekit/gkgamesession/loaddata(completionhandler:).md)
- [save(_:completionHandler:)](gamekit/gkgamesession/save(_:completionhandler:).md)

### Listening for Events

- [add(listener:)](gamekit/gkgamesession/add(listener:).md)
- [remove(listener:)](gamekit/gkgamesession/remove(listener:).md)

### Connecting Players for Real-Time Communication

- [setConnectionState(_:completionHandler:)](gamekit/gkgamesession/setconnectionstate(_:completionhandler:).md)
- [players(with:)](gamekit/gkgamesession/players(with:).md)
- [send(_:with:completionHandler:)](gamekit/gkgamesession/send(_:with:completionhandler:).md)
- [GKTransportType](gamekit/gktransporttype.md)

### Communicating Between Players

- [badgedPlayers](gamekit/gkgamesession/badgedplayers.md)
- [clearBadge(for:completionHandler:)](gamekit/gkgamesession/clearbadge(for:completionhandler:).md)
- [sendMessage(withLocalizedFormatKey:arguments:data:to:badgePlayers:completionHandler:)](gamekit/gkgamesession/sendmessage(withlocalizedformatkey:arguments:data:to:badgeplayers:completionhandler:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Deprecated classes

- [GKAchievementViewController](gamekit/gkachievementviewcontroller.md)
- [GKChallengeEventHandler](gamekit/gkchallengeeventhandler.md)
- [GKChallengesViewController](gamekit/gkchallengesviewcontroller.md)
- [GKChallenge](gamekit/gkchallenge.md)
- [GKScoreChallenge](gamekit/gkscorechallenge.md)
- [GKAchievementChallenge](gamekit/gkachievementchallenge.md)
- [GKCloudPlayer](gamekit/gkcloudplayer.md)
- [GKGameCenterViewController](gamekit/gkgamecenterviewcontroller.md)
- [GKGameSessionSharingViewController](gamekit/gkgamesessionsharingviewcontroller.md)
- [GKFriendRequestComposeViewController](gamekit/gkfriendrequestcomposeviewcontroller.md)
- [GKLeaderboardViewController](gamekit/gkleaderboardviewcontroller.md)
- [GKPeerPickerController](gamekit/gkpeerpickercontroller.md)
- [GKScore](gamekit/gkscore.md)
- [GKSession](gamekit/gksession.md)
- [GKTurnBasedEventHandler](gamekit/gkturnbasedeventhandler.md)
