<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKGameModel/setGameModel(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(pl)GKGameModel(im)setGameModel:"
  },
  "title" : "setGameModel(_:)"
}
-->

# setGameModel(_:)

Sets the game model’s internal state to that of the specified game model.

```
func setGameModel(_ gameModel: any GKGameModel)
```

## Parameters

`gameModel`

The game model instance from which to copy state.

## Discussion

Your implementation of this method should efficiently copy the internal state of the specified object into the current game model.

To examine the results of possible future moves, GameplayKit uses several instances of your game model class and calls the [`setGameModel(_:)`](/documentation/GameplayKit/GKGameModel/setGameModel(_:)) method many times. For example, in a game where seven possible moves are available on each turn, looking only a few turns ahead requires examining hundreds of thousands of board states. (Rather than continually create new instances of your game state class, GameplayKit reuses existing instances by cloning the state of one into another—this optimization improves memory efficiency.)

> Important:
> Because GameplayKit can evaluate thousands of game states each time it plans a move, its performance is limited by the size and complexity of your game model class and its  ``doc://com.apple.gameplaykit/documentation/GameplayKit/GKGameModel/setGameModel(_:)`` method. Ensure that your class contains only data that minimally describes the state of a game in progress and that your ``doc://com.apple.gameplaykit/documentation/GameplayKit/GKGameModel/setGameModel(_:)`` method can copy that data quickly (for example, without creating new objects or allocating memory).

The [`GKGameModel`](/documentation/GameplayKit/GKGameModel) protocol extends the <doc://com.apple.documentation/documentation/Foundation/NSCopying> protocol. Because the [`setGameModel(_:)`](/documentation/GameplayKit/GKGameModel/setGameModel(_:)) method does the critical work of copying the internal state of your game model, you can use this method to implement the requirements of the the <doc://com.apple.documentation/documentation/Foundation/NSCopying> protocol:

```objc
- (__nonnull id)copyWithZone:(nullable NSZone *)zone {
    id<GKGameModel> copy = [[[self class] allocWithZone:zone] init];
    [copy setGameModel:self];
    return copy;
}
```

```swift
func copyWithZone(zone: NSZone?) -> AnyObject {
    let copy = self.dynamicType()
    copy.setGameModel(self)
    return copy
}
```

---

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)