SwiftUI Flashcards
UIViewRepresentable
A protocol used as a wrapper for a UIKit view that you use to integrate that view into your SwiftUI view.
The two methods required for conforming to UIViewRepresentable
makeUIView(context: Context) -> MKMapView
updateUIView(_ uiView: MKMapView, context: Context)
What is needed to communicate between a UIView that conforms to UIViewRepresentable and SwiftUI
class Coordinator: NSObject, MKMapViewDelegate { } makeCoordinator() -> Coordinator
Define @binding
Use a binding to create a two-way connection between a property that stores data and a view that displays and changes the data.
It creates a 2 way binding for the data. So one view can create the data while many other views can read and update that same data.
it lets us declare that one value actually comes from elsewhere, and should be shared in both places.
What’s the purpose @Environment(\.presentationMode) var presentationMode
and how do you use it.
A binding to the current presentation mode of the view associated with this environment.
It allows you to close a sheet with self.presentationMode.wrappedValue.dismiss()
Define @EnvironmentObject
A property wrapper type for an observable object supplied by a parent or ancestor view.
we can place an object into the environment so that any child view can automatically have access to it.
.environmentObject(user)