SwiftUI provides three main approaches for state management: @State for simple local state variables that automatically refresh the UI when changed, @Binding for passing state between parent and child views, @StateObject for managing state in model classes with @Published properties, and @EnvironmentObject for sharing state across multiple view levels without passing parameters.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
State Management in SwiftUI - SwiftUI Basic Tutorial - Ep 4
Added:Hi everyone.
In this video, we are going to see state management in Swift UI.
First, we will see state variable.
Whenever state variable changes, Swift UI automatically refreshes the UI.
Let's see an example.
I have already created a project.
Now, I'm going to modify the content view.
In this sample, I'm going to create and small example where uh it has some count count button, and whenever the increase button is clicked, the text view will be updated.
I'm including the V stack and text view.
And a button.
Naming the button as uh in- increment count.
And include a state variable.
In the text view, I'm including the state variable count.
In the button action, I am in- incrementing the count.
So, now I'm going to give the spacing in the V stack.
So, you can see in the preview it has one button and text view.
Whenever I'm going to click the uh button, it will increment the count value. So, I'm going to click the button.
You can see it increased to one.
And again clicking it, it increased to two. So, whenever the state variable changes, the text view will be updated as it is using the state variable.
Now, we are going to see another scenario.
Suppose, this button is in the child view.
In that case, how we can manage?
So, I'm going I'm going to create a child view.
I'm in I'm copy pasting to child view.
And now we are going to pass count to the child view. For that, we have to include binding.
Now, include the child view in the parent.
Okay. To pass the To pass value to the binding, we have to include dollar symbol.
Okay.
Now, I'm going to click the button and value will be increased.
Next, we are going to see state object and observed object.
Suppose, this count value is in the model. In that case, how we can manage?
I'm going to create a class.
Name it as counter model.
And where count and it will be zero.
Suppose, value is in the is in the this uh counter model.
In this case In this case, how we can manage is we can use state object.
For that, we have to extend counter model into observable object.
And we have to mention count as published.
For including the observable object, we have to import combine.
To initialize model, we have to make the model as state object.
Counter model.
First we will do in the parent view itself.
Next we will go for child view.
I'm including the button in the parent view itself.
So, So, when I'm in clicking the button, the text will be increased.
Here, whenever the published variable in the model is updated, the view which is using the variable will be updated.
Next, we will include the button in the child view.
So, I'm I'm including in the child view.
So, to pass the state object into the child view, we have to include observed object.
>> We can pass the model into the child view.
Now, we can uh see the output in the preview. So, I'm clicking the button.
We can see text view is increased.
Next, we are going to see environment object supports We have to pass model into the uh from parent to child when there is multiple level of uh uh parent-child uh views, then we can use environment object.
Here, in the child view we have to mention environment object and we no need to pass in the parameter.
You have to assign in the V stacks environment object.
So, now we can check the preview.
I'm clicking the button.
So, text view is increased.
So, in this case we can uh use the environment object.
Thanks for watching this video.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23