@State property in SwiftUI

Property Wrappers?

What is it?

@State private var iLovePizza: Bool = true
@State private var iLovePizza: Bool = truevar body: some View {  VStack {
if iLovePizza {
Text("I Love Pizza 🍕")
} else {
Text("🍕 = Nada")
}

Button("Toggle") {
iLovePizza.toggle()
}
}
}

Binding

@State private var name: String = ""var body: some View {
VStack(alignment: .leading) {
Text("My Name is \(name)")
TextField("Enter your name", text: $name)
}.padding()
}

A Software Engineer with a passion for technology. Working as an iOS Developer @BBC

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

This is the biggest Swift cheat sheet

How to Build an App for watchOS With No-code Tools?

Popular iPhone applications built with Swift

macOS, a developer’s point of view about Big Sur, news and bugs that I have personally encountered.

How to make a iPhone app / game

Multi window SwiftUI macOS app working with menu commands

The Making of a Carplay Audio Application

Swift Packager Manager ignores Swift file

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Melvin John

Melvin John

A Software Engineer with a passion for technology. Working as an iOS Developer @BBC

More from Medium

Guide to manage secrets in SwiftUI app

New configuration file

Send data with navigation from View controller to SwiftUI view

Protecting ImageView content on iOS

Implementing A Custom Formatter in Swift