Follow along at https://www.hackingwithswift.com/100/swiftui/73.
This day covers Part Six of Project 14
in the 100 Days of SwiftUI Challenge. (Project 14 files can be found in the directory for Part One.)
In addition to recapping the material covered during the project's other days, Day 67 focuses on extending the project according to a set of challenges.
Our + button is rather hard to tap. Try moving all its modifiers to the image inside the button – what difference does it make, and can you think why?
We don't quite need to put all modifiers inside the button -- but certainly the ones that would determine the surface area of the content:
Button(action: {
self.createNewLocation()
}) {
Image(systemName: "plus.rectangle.fill")
.font(.title)
.padding(24)
.background(Color.accentColor.opacity(0.8))
.foregroundColor(.white)
}
.clipShape(Circle())
.padding(.trailing)
- 🔗 Commit
Having a complex
if
condition in the middle ofContentView
isn’t easy to read – can you rewrite it so that theMapView
,Circle
, andButton
are part of their own view?
TBH, ContentView
is usually the first file I delete in a new project 😂. Organizing views under a Scenes
folder and also composing them from various "container views" can go a long way to preventing the sort of problem mentioned above.
With a container view that handles authentication, it can conditionally show an "authed" view which, itself, is solely focused on its standard layout:
struct LocationCollectionView: View {
var body: some View {
ZStack {
mapUnderlay
centerIndicator
addLocationButton
}
}
}
Our app silently fails when errors occur during biometric authentication. Add code to show those errors in an alert. But be careful: you can only add one alert() modifier to each view.
- 🔗 Commit