100 Days of SwiftUI
2026-07-26
Project 14, part 6
Bucket List wrap up
Quiz: 11/12
Challenge
- Allow the user to switch map modes, between the standard mode and hybrid.
This was a little more difficult than I expected, first because MapStyle isn’t Equatable so I couldn’t just use a ternary on currentStyle. I also had difficulties landing the button
@State private var isHybrid = false
***
.safeAreaInset(edge: .top, alignment: .trailing) {
Button("", systemImage: "map") {
isHybrid.toggle()
}
.accessibilityLabel(isHybrid ? "Show standard map" : "Show hybrid map")
.padding()
.buttonStyle(.borderedProminent)
}
.mapStyle(isHybrid ? .hybrid : .standard)
- Our app silently fails when errors occur during biometric authentication, so add code to show those errors in an alert.
This was a bit more difficult because I wasn’t sure where the logic was supposed to go — it needs to be in the ViewModel class (to define variables) authentication() method (to set variables). Then the alert modifier goes on the Unlock button.
- Create another view model, this time for
EditView. What you put in the view model is down to you, but I would recommend leavingdismissandonSavein the view itself — the former uses the environment, which can only be read by the view, and the latter doesn’t really add anything when moved into the model.
This is a matter of taking most everything out of the EditView and then remembering to add viewModel. as a prefix to items in the EditView