Instance Method


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



- (void)setGameModel:(id<GKGameModel>)gameModel;



The game model instance from which to copy state.


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: 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.)

The GKGameModel protocol extends the NSCopying protocol. Because the 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 NSCopying protocol:

- (__nonnull id)copyWithZone:(nullable NSZone *)zone {
    id<GKGameModel> copy = [[[self class] allocWithZone:zone] init];
    [copy setGameModel:self];
    return copy;
func copyWithZone(zone: NSZone?) -> AnyObject {
    let copy = self.dynamicType()
    return copy

See Also

Modifying a Game Model

- applyGameModelUpdate:

Updates the internal state of the game model to reflect the specified changes.


- unapplyGameModelUpdate:

Updates the internal state of the game model to remove the effect of the specified changes.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software