SpriteKit Save Files in Swift 3
Last year I wrote about saving game data in SpriteKit, and that code is now completely out of date. Swift 3 has brought about all sorts of fun changes, so it’s time for me to provided some updated code.
The general approach remains the same — conform save data to NSCoding and write to a plist file. The main changes / improvements are:
- You have to manually create an empty DefaultFile.plist in your project directory
- Uses new singleton implementation
- You have to use encodeInteger / Double / Bool instead of just encodeObject
- Swift 3 syntax changes
You can read my last post for more context, or jump straight to the gist below. First, code calling the GameData class.
Then, you can look at the GameData and Level class here:
[…] NOTE: This article has been updated. Refer to SpriteKit Saving with Swift 3 […]
How to create a level ?