Most iOS code in the world is UIKit, and most professional iOS work is on an app that already exists. You will meet UIViewController and its lifecycle - viewDidLoad once, viewWillAppear every time the screen is about to show, viewDidDisappear when it leaves - and the common bug of putting setup in viewWillAppear, where it runs again every time the reader comes back.
Where SwiftUI describes layout, UIKit constrains it: Auto Layout is a system of equations relating edges, and translatesAutoresizingMaskIntoConstraints = false is the line everyone forgets, which makes the constraints you then add conflict with ones the system generated for you.
The two frameworks interoperate in both directions, and you will use both wrappers. UIViewRepresentable and UIViewControllerRepresentable put a UIKit view inside SwiftUI - this is how you get MKMapView, PHPickerViewController, or a third-party control whose SwiftUI version does not exist yet. A Coordinator carries the delegate callbacks back across. In the other direction, UIHostingController wraps a SwiftUI view so it can be pushed onto a UINavigationController, which is how new screens get added to an old app one at a time.
import SwiftUI
import MapKit
// A UIKit view used from SwiftUI. The Coordinator carries delegate callbacks.
struct MapPane: UIViewRepresentable {
@Binding var region: MKCoordinateRegion
func makeUIView(context: Context) -> MKMapView {
let map = MKMapView()
map.delegate = context.coordinator
map.setRegion(region, animated: false)
return map
}
// Called when SwiftUI state changes and the UIKit view needs to catch up.
func updateUIView(_ map: MKMapView, context: Context) {
if map.region.center.latitude != region.center.latitude {
map.setRegion(region, animated: true)
}
}
func makeCoordinator() -> Coordinator { Coordinator(self) }
final class Coordinator: NSObject, MKMapViewDelegate {
private let parent: MapPane
init(_ parent: MapPane) { self.parent = parent }
func mapView(_ map: MKMapView, regionDidChangeAnimated animated: Bool) {
// Back across the boundary, onto the main actor.
Task { @MainActor in parent.region = map.region }
}
}
}
// The other direction: a SwiftUI screen pushed onto a UIKit stack.
final class LegacyListController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad() // once, when the view is created
}
func showDetail() {
let swiftUIScreen = UIHostingController(rootView: ArticleListView())
navigationController?.pushViewController(swiftUIScreen, animated: true)
}
}