SwiftUI | Sheetly Cheat Sheet

Last Updated: November 21, 2025

SwiftUI

Modern iOS/macOS UI framework

Basic Views

import SwiftUI

struct ContentView: View {
    @State private var name = ""
    @State private var isToggled = false
    
    var body: some View {
        VStack(spacing: 20) {
            Text("Hello, World!")
                .font(.largeTitle)
                .foregroundColor(.blue)
            
            Image(systemName: "star.fill")
                .resizable()
                .frame(width: 50, height: 50)
            
            TextField("Enter name", text: $name)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .padding()
            
            Toggle("Enable Feature", isOn: $isToggled)
            
            Button("Submit") {
                print("Submitted: \(name)")
            }
            .buttonStyle(.borderedProminent)
        }
        .padding()
    }
}

State Management

Item Description
@State Local mutable state
@Binding Two-way binding to parent state
@ObservedObject External observable object
@StateObject Owned observable object
@EnvironmentObject Shared app-wide state
@Environment System environment values

Layout Containers

Item Description
VStack Vertical stack
HStack Horizontal stack
ZStack Depth stack (overlapping)
List Scrollable list
ScrollView Scrollable container
LazyVStack/HStack Lazy loading stack
Grid Grid layout

Modifiers

Text("Styled Text")
    .font(.title)
    .fontWeight(.bold)
    .foregroundColor(.blue)
    .padding()
    .background(Color.gray.opacity(0.2))
    .cornerRadius(10)
    .shadow(radius: 5)
    .frame(width: 200, height: 50)
    .onTapGesture {
        print("Tapped")
    }

Navigation

NavigationStack {
    List {
        NavigationLink("Detail View") {
            DetailView()
        }
    }
    .navigationTitle("Home")
    .navigationBarTitleDisplayMode(.large)
}

💡 Pro Tips

Quick Reference

SwiftUI automatically updates views when state changes

← Back to Programming Languages | Browse all categories | View all cheat sheets