I have the following snippet of SwiftUI code using MapKit for iOS using MacOS Catalyst mode. The output of the code shows a large white box with the MapKit but that is not shown in the MacOS version using Cocoa with NS instead of UI. What is the problem?
import SwiftUI
import MapKit
struct ContentView: View {
@State var date = Date()
var body: some View {
HStack {
NavigationView {
MapView()
.edgesIgnoringSafeArea(.all)
}
VStack(alignment: .leading) {
...
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct MapView: UIViewRepresentable {
typealias NSViewType = MKMapView
// 1.
func makeUIView(context: UIViewRepresentableContext<MapView>) -> MKMapView {
MKMapView(frame: .zero)
}
// 2.
func updateUIView(_ uiView: MKMapView, context: UIViewRepresentableContext<MapView>) {
// 3.
let location = CLLocationCoordinate2D(latitude: 30.0,
longitude: 0.0)
// 4.
let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
let region = MKCoordinateRegion(center: location, span: span)
uiView.setRegion(region, animated: true)
// 5.
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = "Big Ben"
annotation.subtitle = "London"
uiView.addAnnotation(annotation)
}
}