Instance Method

saveGameData(_:withName:completionHandler:)

Saves game data under the specified name.

Declaration

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

Parameters

data

An object that contains the saved game data.

name

A string that identifies the saved game data.

handler

A block to be called when the request completes.

The block receives the following parameters:

savedGame

A GKSavedGame object containing saved game information for the saved data.

error

If an error occurred, this parameter holds an error object that explains the error. Otherwise, the value of this parameter is nil.

Discussion

This method saves game data asynchronously. When a game is saved, if there is already a saved game with the same name, the new saved game data overwrites the old saved game data. If there is no saved game with the same name, a new saved game is created.