100 Days of SwiftUI
2026-06-23
Project 10, part 2
A few more techniques…
Adding Codable conformance to an @Observable class
This was very Gingery. However, I think the gist of it is: @Observable is a macro that adds a lot of code. When you encode/decode JSON you’ll get a lot of extra stuff. Use a pattern like this to specify exactly what you’re wanting:
@Observable
class myClass: Codable {}
enum CodingKeys: String, CodingKey {
case key_from_observable = key_you_want_to_use
}
var key_you_want_to_use = default_item
}Note that CodingKeys / CodingKey are the required words
Adding haptic effects
- make stuff vibrate!!
- two options: Easy, Complete
- probably will want to stick with Easy
- they ONLY WORK ON PHYSICAL iPHONES
- use the modifier
.sensoryFeedback()on, say, a button. there are various types and they all have a different response- don’t pick your own, stick with the given contexts if they are appropriate for your app (otherwise you can confuse users)
- you can customize this a bit with
.impact()instead of picking a context
- the Complete version uses
CoreHaptics- looks like fun, but it’s really complicated
Taking basic order details
Now on to the app!
- create an
Orderclass (with@Observable) to handle the data among all of the screens
For now this class won’t need many properties:
- The type of cakes, plus a static array of all possible options.
- How many cakes the user wants to order.
- Whether the user wants to make special requests, which will show or hide extra options in our UI.
- Whether the user wants extra frosting on their cakes.
- Whether the user wants to add sprinkles on their cakes.
So far it’s much like we’ve done before — the only “new” bit is adding in conditional visibility