What iOS and Swift are and how they work
Apps for iPhone and iPad are written in Swift — an Apple language where types are checked at build time, the absence of a value is expressed with optionals and memory is managed by the language itself. The interface is described declaratively in SwiftUI: what to show for the current data, and the framework updates the screen.
A native app in Swift and SwiftUI is the choice when the product lives on iPhone and iPad and has to get new system features straight away. Swift is written for servers too, but an iPhone app is built in Xcode — Apple’s development environment for the Mac, with an editor, device simulators in the Device Hub, a debugger and the Instruments profiler. If one team builds for iOS and Android at once, compare with the cross-platform route — it is covered in the Flutter reference, the section “What Flutter is and how it works”.
A SwiftUI app is a tree of types. A structure with the @main attribute implements the App protocol and lists scenes (Scene); the WindowGroup scene creates windows with a root view from which the view hierarchy grows. Data lives separately: a model with the @Observable macro holds the state, while a data layer — SwiftData, URLSession and the keychain — loads and saves it. When the data changes, SwiftUI itself updates the parts of the interface that depend on it.
import SwiftUI @Observablefinal class NoteStore { var notes: [String] = ["Buy milk"]} @mainstruct NotesApp: App { // the model is created once and lives as long as the app @State private var store = NoteStore() var body: some Scene { WindowGroup { ContentView() .environment(store) } }} struct ContentView: View { @Environment(NoteStore.self) private var store var body: some View { List(store.notes, id: \.self) { note in Text(note) } }}How SwiftUI differs from UIKit
| Feature | SwiftUI | UIKit |
|---|---|---|
| How the interface is described | declaratively: which views to show for this data | imperatively: view controller code creates the views and changes them |
| Who updates the screen | the framework, when the data changes | the code of the view controller |
| How to embed the other | a UIKit view — via UIViewRepresentable and UIViewControllerRepresentable | a SwiftUI screen — via UIHostingController |
Choose SwiftUI for a new app: it does most of the work view controllers used to do. UIKit stays where it already exists and for components SwiftUI lacks; both frameworks work in one app, so nothing has to be rewritten all at once.
What to know beforehand
- Programming basics: variables, functions, conditionals and loops. The language itself — in the section “Swift syntax”.
- How HTTP requests and JSON work — the HTTP and REST reference.
- Working with a code repository — the Git reference.
Section sources
the section is written from these pages- Appdeveloper.apple.com/documentation/swiftui/app(opens in a new tab)
- Model datadeveloper.apple.com/documentation/swiftui/model-data(opens in a new tab)
- UIKit integrationdeveloper.apple.com/documentation/swiftui/uikit-integration(opens in a new tab)
- About Swiftdocs.swift.org/6.4/documentation/the-swift-programming-language/aboutswift/(opens in a new tab)
- Xcodedeveloper.apple.com/xcode/(opens in a new tab)