Follow along at https://www.hackingwithswift.com/100/swiftui/52.
This day covers Part Four of Project 10: CupcakeCorner
in the 100 Days of SwiftUI Challenge. (Project 10 files can be found in the directory for Part One.)
In addition to recapping the material covered during the project's other days, Day 52 focuses on extending the project according to a set of challenges.
Our address fields are currently considered valid if they contain anything, even if it’s just only whitespace. Improve the validation to make sure a string of pure whitespace is invalid.
- 🔗 Commit
If our call to
placeOrder()
fails – for example if there is no internet connection – show an informative alert for the user. To test this, just disable WiFi on your Mac so the simulator has no connection either.
- (Already covered 🙂)
For a more challenging task, see if you can convert our data model from a class to a struct, then create an
ObservableObject
class wrapper around it that gets passed around. This will result in your class having one@Published
property, which is the data struct inside it, and should make supporting Codable on the struct much easier.
- Sort of already covered 🙂. I commented on the approach I took with this in Day 49)