At this point, you have learned how to create text views and image views for your app. Now let's see how to add a view that displays a map. When using storyboards, all you needed to do was to drag in a map view from the Object library to a view in storyboard. SwiftUI does not have a native map view but you can use the same map view that you used in storyboard to render the map. In fact, you can use any view subclass within SwiftUI by wrapping them in a SwiftUI view that conforms to the UIViewRepresentable protocol. You'll create a new custom view that can present a map view now. Do the following steps:
- Choose File | New | File to open the template selector.
- iOS should already be selected. In the User Interface section, click to select SwiftUI View and click Next.
- Name the new file MapView.swift and click Create.
- In MapView.swift...