← All courses

Views and the View Lifecycle

🗓 May 31, 2026 ⏱ 1 min read

SwiftUI: views are data

In SwiftUI a screen is a struct that describes what to show. When your data changes, SwiftUI redraws automatically.

struct CounterView: View {
    @State private var count = 0
    var body: some View {
        VStack {
            Text("Count: \(count)")
            Button("Add") { count += 1 }
        }
    }
}

UIKit: the controller lifecycle

In UIKit a screen is a UIViewController. These methods fire as it appears:

  • viewDidLoad() — called once, set up your UI here.
  • viewWillAppear() — just before the screen shows.
  • viewDidDisappear() — after it leaves the screen.
Tip: @State in SwiftUI replaces a lot of manual lifecycle work — change the value and the UI updates itself.