SwiftUI Fundamentals

Feb 28 2023 · Swift 5.7, macOS Venture 13.1, Xcode 14.2

Part 1: SwiftUI Views

05. State & Binding

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 04. Challenge: Views & Modifiers Next episode: 06. Challenge: State & Binding

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

So far you’ve been working with views that don’t really do anything. They aren’t interactive. They don’t affect anything else and nothing affects them. Let’s try out something a little more complicated. Like, using a color picker to update the color of an image.

ColorPicker(/*@START_MENU_TOKEN@*/"Title"/*@END_MENU_TOKEN@*/, selection: /*@START_MENU_TOKEN@*/.constant(.red)/*@END_MENU_TOKEN@*/)
ColorPicker("Swifty Color", ...
struct ContentView: View {
  var swiftyColor: Color = .red
struct ContentView: View {
  @State var swiftyColor: Color = .red
selection: swiftyColor
$swiftyColor
.background(swiftyColor)
@State var swiftyOpacity: Double = 0.7
Slider(value: $swiftyOpacity, in: 0...1)
.accentColor(swiftyColor)
.opacity(swiftyOpacity)
@State var swiftyOpacity: Double = 0.7
@State var swiftyColor: Color = .red
@Binding var swiftyOpacity: Double
@Binding var swiftyColor: Color
@State 🟢private var swiftyOp
@State 🟢private var swiftyCo
SwiftyControls(
  swiftyOpacity: $swiftyOpacity,
  swiftyColor: $swiftyColor
)