Place markers on a map with places you want to visit before hitting... the bucket.
- SwiftUI
- MapKit & SwiftUI integration using UIViewRepresentable
- LocalAuthentication (TouchID & FaceID)
Adding conformance to Comparable to our data model requires providing an implementation to the < function:
struct User: Identifiable, Comparable {
let id = UUID()
let firstName: String
let lastName: String
static func < (lhs: User, rhs: User) -> Bool {
lhs.lastName < rhs.lastName
}
}
And now we get sorted for free. This is a much better/cleaner option compared to messing with the data structure in the Views.
We can model our view states in an enum, however instead of 'switching' on it we have to:
Group {
if loadingState == .loading {
LoadingView()
} else if loadingState == .success {
SuccessView()
} else if loadingState == .failed {
FailedView()
}
}
MKMapView is an UIView, so we have to make use of the UIViewRepresentable protocol. And then add the Coordinator class in order to implement the delegate methods.
Import the LocalAuthentication library.
https://www.hackingwithswift.com/books/ios-swiftui/using-touch-id-and-face-id-with-swiftui
extension MKPointAnnotation: ObservableObject {
public var wrappedTitle: String {
get {
self.title ?? "Unknown value"
}
set {
title = newValue
}
}
public var wrappedSubtitle: String {
get {
self.subtitle ?? "Unknown value"
}
set {
subtitle = newValue
}
}
}
- 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?
- Having a complex if condition in the middle of ContentView isn’t easy to read – can you rewrite it so that the MapView, Circle, and Button are part of their own view? This might take more work than you think!
- 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.