SwiftUI #1

uniqueness, basic components, layout, modifiers

Functional Programming

  • SwiftUI is functional
  • Functional vs Imperative
  • SwiftUI is reactive

Create your View

struct ContentView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

Basic Components

  • Text
  • Button
  • Image
  • Color

Layouts

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, World!")

            Button("Tap Me") {
                // Imperative calls
            }
        }
    }
}

Layouts

  • Also HStack, ZStack
  • Grid
  • ScrollView

Modifiers

  • Make changes to a view
  • Returns a View!
  • Apply 99+ standard modifiers (in Library)
  • Can create custom modifiers too

State

  • Declare with @State var
  • Change the state -> View will react accordingly

Binding

  • State is the source-of-truth
  • Binding is the "reference type" to the state