Spring SALE
Memento

Memento in Swift

Memento is a behavioral design pattern that allows making snapshots of an object’s state and restoring it in future.

The Memento doesn’t compromise the internal structure of the object it works with, as well as data kept inside the snapshots.

Complexity:

Popularity:

Usage examples: The Memento’s principle can be achieved using serialization, which is quite common in Swift. While it’s not the only and the most efficient way to make snapshots of an object’s state, it still allows storing state backups while protecting the originator’s structure from other objects.

The following examples are available on Swift Playgrounds.
Kudos to Alejandro Mohamad for creating the Playground version.

Memento in Other Languages

Memento in C# Memento in C++ Memento in Go Memento in Java Memento in PHP Memento in Python Memento in Ruby Memento in Rust Memento in TypeScript