<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameKit",
  "identifier" : "/documentation/GameKit/GKLocalPlayer/saveGameData(_:withName:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKLocalPlayer(im)saveGameData:withName:completionHandler:"
  },
  "title" : "saveGameData(_:withName:completionHandler:)"
}
-->

# saveGameData(_:withName:completionHandler:)

Saves game data with the specified name.

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

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

- savedGame: The saved game.
- error: Describes an error if it occurs, or `nil` if the operation completes.

## 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 <doc://com.apple.documentation/documentation/BundleResources/Entitlements/com.apple.developer.icloud-container-identifiers> key to your project containing a unique identifier for your game.

---

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)