---
title: "saveGameData(_:withName:completionHandler:)"
framework: gamekit
role: symbol
role_heading: Instance Method
path: "gamekit/gklocalplayer/savegamedata(_:withname:completionhandler:)"
---

# saveGameData(_:withName:completionHandler:)

Saves game data with the specified name.

## Declaration

```swift
func saveGameData(_ data: Data, withName name: String, completionHandler handler: (@Sendable (GKSavedGame?, (any Error)?) -> Void)? = nil)
```

```swift
func saveGameData(_ data: Data, withName name: String) async throws -> GKSavedGame
```

## Parameters

- `data`: An object that contains the saved game data.
- `name`: A unique filename for the saved game data.
- `handler`: The block that this method calls when it completes the request. The block receives the following parameters:

## Mentioned in

Saving the player’s game data to an iCloud account

## Discussion

Discussion If the name parameter is an existing filename, GameKit overwrites the file with the new game data. important: You must provide an iCloud container ID in your project to save game data to the player’s iCloud account. Add the iCloud Container Identifiers Entitlement key to your project containing a unique identifier for your game.

## See Also

### Saving Game Data

- [Saving the player’s game data to an iCloud account](gamekit/saving-the-player-s-game-data-to-an-icloud-account.md)
- [fetchSavedGames(completionHandler:)](gamekit/gklocalplayer/fetchsavedgames(completionhandler:).md)
- [resolveConflictingSavedGames(_:with:completionHandler:)](gamekit/gklocalplayer/resolveconflictingsavedgames(_:with:completionhandler:).md)
- [deleteSavedGames(withName:completionHandler:)](gamekit/gklocalplayer/deletesavedgames(withname:completionhandler:).md)
- [GKSavedGame](gamekit/gksavedgame.md)
- [GKSavedGameListener](gamekit/gksavedgamelistener.md)
