Swift 6 · SwiftUI basics

A simple view

A SwiftUI view returns its content from body. State changes re-render it.

import SwiftUI

struct CounterView: View {
    @State private var count = 0

    var body: some View {
        VStack(spacing: 12) {
            Text("Count: \(count)")
            Button("Add") { count += 1 }
        }
        .padding()
    }
}

Official Swift 6 documentation

More swiftui basics commands

All swiftui basics commands · Swift 6 cheatsheet

Was this page helpful?