Here is a nice implementation of undo functionality in swift by Chris Eidhof: http://chris.eidhof.nl/post/undo-history-in-swift/
The current implementation has a few limitations (supports only structs, stores the whole object, not just the change). But it is only a demo for an idea. Use it accordingly.