Dev Skill Programme
Mobile guides

iOS Fundamentals

Swift, the app lifecycle, and how SwiftUI decides what to draw.

Concept guideUpdated 21 days ago (29 Sept 2026) by Developer D

iOS Fundamentals

Swift in one page

  • Optionals are the type system telling you a value may be absent. Unwrap deliberately; ! is a promise you will be held to at runtime.
  • Structs are values, classes are references. Prefer structs. Reach for a class when you need identity or shared mutable state.
  • Protocols describe capability, not hierarchy.

App lifecycle

An app is not simply "open" or "closed":

StateWhat it means
Not runningNever launched, or terminated
InactiveForeground but not receiving events
ActiveForeground and interactive
BackgroundRunning briefly with limited time
SuspendedIn memory, not executing — can be killed silently

Anything you have not saved before suspension can disappear.

SwiftUI is declarative

You describe what the UI should look like for a given state; the framework works out the changes. You do not mutate views.

struct LevelBadge: View {
    let level: Int

    var body: some View {
        Text("L\(level)")
            .font(.caption.weight(.semibold))
            .padding(.horizontal, 8)
            .padding(.vertical, 2)
            .background(Capsule().fill(.quaternary))
    }
}

State ownership

  • @State — this view owns it.
  • @Binding — someone else owns it, this view may change it.
  • @Observable / @StateObject — a model object with a longer life.

Hoist state to the lowest common ancestor that needs it, and no higher.