SwiftUI #3

Persistency, animation

Persistency

  • Persist data upon app relaunch
class Book: ObservableObject {
    @AppStorage("page") var page = 1 // Persisted
    @Published var title = "Great Expectations" // Not persisted
}

1. Animation for a view

someView
  .animation(.spring(), value: showDetail)

2. Animation to a state change

Button("Change") {
    withAnimation {
        showDetail.toggle()
    }
}