UIKit and AppKit Overview
UIKit (iOS/iPadOS/tvOS/visionOS) and AppKit (macOS) are the imperative, object-oriented frameworks that predate SwiftUI. They're still essential for many apps and integrate with SwiftUI.
Core concepts: view controller lifecycle (viewDidLoad, viewWillAppear...), Auto Layout, UITableView/UICollectionView (diffable data sources, compositional layout), delegates/data sources, navigation/tab controllers, storyboards vs programmatic UI, UIApplicationDelegate/UISceneDelegate.
Interop: UIHostingController(rootView:) (SwiftUI inside UIKit), UIViewRepresentable/UIViewControllerRepresentable (UIKit inside SwiftUI), and the AppKit equivalents (NSHostingView, NSViewRepresentable).
import UIKit
final class ProfileViewController: UIViewController {
private let nameLabel = UILabel()
private let button = UIButton(configuration: .filled())
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
nameLabel.text = "Ana"
nameLabel.font = .preferredFont(forTextStyle: .title1)
button.configuration?.title = "Edit"
button.addAction(UIAction { [weak self] _ in self?.edit() }, for: .touchUpInside)
let stack = UIStackView(arrangedSubviews: [nameLabel, button])
stack.axis = .vertical
stack.spacing = 12
stack.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stack)
NSLayoutConstraint.activate([
stack.centerXAnchor.constraint(equalTo: view.centerXAnchor),
stack.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
private func edit() { navigationController?.pushViewController(EditViewController(), animated: true) }
}