Follow along at https://www.hackingwithswift.com/100/50.
This day resolves around recapping the content covered while going through Projects 10-12 in Hacking with Swift, and then implementing a challenge project. Regarding the recap, I won't try to rehash what I wrote up already — but a few extra things are worth noting.
- When
touchesBegan
is called in a SpriteKitGameScene
, it has the following signature:
func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
The touches
set is guaranteed to contain at least one touch, so we can use implicit unwrapping of Array.first
without much concern:
let touch = touches.first!
While UserDefaults
provides a type-safe getters for "simple" types — and even an array of strings — getting more complex objects is a different story.
let photos = UserDefaults.standard.object(forKey: "Photos") as? [Photo] ?? [Photo]()
If you weren't good at nil coalescing before, you will be now 😛.
From https://www.hackingwithswift.com/guide/5/3/challenge:
Put two different projects into one: Let users take photos of things that interest them, add captions to them, then show those photos in a table view. Tapping the caption should show the picture in a new view controller.
Feel free to peruse the finished project here ✌️.