Data Flow in a SwiftUI App

  Переглядів 51,552

CodeWithChris

CodeWithChris

День тому

In this lesson I want to review with you how data both plays a part in your view and also how it flows through your app across multiple views.
We’ll start with the simplest scenario and work our way to more complex scenarios.
You’ll see examples using state properties, bindings, observable objects, environment objects as well as other data related SwiftUI keywords such as @Published, @ObservedObject and more.
By the end, you’ll know how to pass data around in your SwiftUI app!
🚨 SPECIAL CWC+ OFFER FOR UKposts:
cwc.to/youtubeoffer
Timestamps:
00:00 Introduction
00:57 SwiftUI State Properties
03:20 State Properties Recap
03:38 SwiftUI Bindings
04:10 $Binding Example
06:51 $Bindings Recap
07:05 @Binding Example
14:42 $Binding and @Binding Recap
15:15 SwiftUI State and Bindings Recap
15:45 SwiftUI ObservableObjects
17:31 ObservableObject Example
22:55 ObservableObject Recap
26:33 SwiftUI EnvironmentObject
28:07 EnvironmentObject Example
30:28 EnvironmentObject Recap
32:39 Outro
MY FREE ONLINE COURSE:
⚡ How to make an app in 14 days - cwc.to/14days
CWC+ PROGRAM:
👩‍💻 All our courses in a learning path - cwc.to/plus
WEEKLY UPDATES VIA EMAIL:
✉️ Every Saturday, receive an email digest of new content - cwc.to/newsletter
CONNECT:
🌍 Website - codewithchris.com
😺 GitHub - github.com/codewithchris
📸 Instagram - / codewithchris
🐦 Twitter - / codewithchris
ABOUT CODEWITHCHRIS:
Hi I’m Chris! I’m dedicated to teaching fundamentals about how to make an app. This is important if you’re trying to land an iOS job, be a freelancer, increase or start a business with an app idea. On this channel and my website, you'll find a ton of free resources and tutorials to aid you on your journey to learn iOS development. Many people have learned to code and build apps on their own! cwc.to/reviews
DID THESE LESSONS HELP YOU?
Please let me know! - feedback.codewithchris.com
ROADMAP:
roadmap.codewithchris.com

КОМЕНТАРІ: 145
@F34R303
@F34R303 19 днів тому
I started watching your videos 6 years ago when I was in high school to learn coding. Now, I've graduated college, working as a software engineer and am still learning a ton from your videos!
@andriybelizky9318
@andriybelizky9318 4 місяці тому
Great video - I love it how it shows different scenarios and various tools used to solve issues
@shrutisharma3341
@shrutisharma3341 2 роки тому
This video deserved so many more likes. This literally cleared out all of my data flow confusions with swift UI! Thanks a ton!!
@CodeWithChris
@CodeWithChris 2 роки тому
Ahhhh, thank you so so much! Makes all the hard work so worth it. :) -Arthur
@JacobSucksAtCode
@JacobSucksAtCode 11 місяців тому
Dude your walkthroughs are so good. Super thorough, relaxing and information filled!
@CodeWithChris
@CodeWithChris 11 місяців тому
Glad you like them! - Pat
@armaanr1656
@armaanr1656 2 роки тому
This cleared up all of my confusions. Best tutorial on youtube. Keep it up Chris🙂!
@CodeWithChris
@CodeWithChris 2 роки тому
This comment made our day. Thanks for learning with us! -Arthur
@nindz9272
@nindz9272 2 роки тому
Thank you so much for this video! Just yesterday I was googling the exact things you've described in this video. It really does help to understand how things work in SwiftUI.
@CodeWithChris
@CodeWithChris 2 роки тому
Glad you found us. We're so excited for you! :) -Arthur
@zlatkoiliev8927
@zlatkoiliev8927 Рік тому
I finally managed to understand them all! Thank you so much for this tutorial Chris! You are awesome! :)
@CodeWithChris
@CodeWithChris Рік тому
We're happy to help! And thanks for watching! :) - Pat
@susantasahoo4702
@susantasahoo4702 2 роки тому
Awesome video. This literally cleared out all of my data flow confusions with swift UI! Thanks a ton!! It deserves many more likes. Best video on this topic. Appreciate your effort for explaining it in nice & clean Manner.
@CodeWithChris
@CodeWithChris 2 роки тому
Glad to hear this, Susanta! Thanks for learning with us! -Arthur
@arkemal
@arkemal Рік тому
Man, your explanations are excellent. Thank you for this!
@CodeWithChris
@CodeWithChris Рік тому
You're welcome!!! - Pat
@SebastienBarrau
@SebastienBarrau Рік тому
Thanks for the awesome video on environmentObjects. You made it super easy to understand and I appreciate the time and effort you put into making it. Keep up the great work!
@CodeWithChris
@CodeWithChris Рік тому
Thank you so much for the kind words! :) - Pat
@codingkim5714
@codingkim5714 2 роки тому
Hi, Cris. Thank you for uploading these about Swift. I'd beed desperate till I found your channel. I found the best videos for starting to study the Swift! Awesome!
@CodeWithChris
@CodeWithChris 2 роки тому
So kind of you! Thank you so so much! -Arthur
@santoshlohar152
@santoshlohar152 8 місяців тому
Dude you explained in easy way..thanks.
@PierluigiLuceri
@PierluigiLuceri 9 місяців тому
thanks a lot, this is the best video about data flow in swiftui, great job
@joeybodnar
@joeybodnar 2 роки тому
I took your 2 initial iOS courses 6 years about back in 2015 and been working as a professional iOS dev for 5yrs now. came back to learn swiftUI. still high quality content, nice! wish I could like this video multiple times.
@CodeWithChris
@CodeWithChris 2 роки тому
Aaaaah, your comment made our day. Thank you for learning with us! Your support means a lot! :) -Arthur
@mario_luis_dev
@mario_luis_dev 2 місяці тому
masterful explanation Chris! 👏
@nzbszb
@nzbszb Рік тому
This is very detailed, simplified and well explained. Others always tried (no offence!) but failed to give good examples like this. Thanks for this treasure.
@CodeWithChris
@CodeWithChris Рік тому
Thank you for the kind words! We do our best to explain as simply as possible. @AdrienVillez
@balazskepli9471
@balazskepli9471 7 місяців тому
Very good summary on data flow! Thank you!
@CodeWithChris
@CodeWithChris 7 місяців тому
Glad it was helpful! Thanks for learning with us! - Iñaki
@GamingSucks
@GamingSucks 2 роки тому
What an incredibly clear explanation. The examples really bring it together. Quite possibly the best I have seen on UKposts!
@CodeWithChris
@CodeWithChris 2 роки тому
Aaaaah, our team appreciates your support, Rick! Thank you for your very kind comment! :) -Arthur
@DaveJacobseniOS
@DaveJacobseniOS 2 роки тому
Such quality explanations. Thank you as always!
@CodeWithChris
@CodeWithChris 2 роки тому
Great to know this. Thank you for the kind words! -Arthur
@georgh.9814
@georgh.9814 2 роки тому
Thank you so much! Exactly what i was searching for and so well descriped!.
@CodeWithChris
@CodeWithChris 2 роки тому
You are so welcome! :) -Arthur
@user-om1ze4mi7u
@user-om1ze4mi7u Рік тому
This was an amazing video for developers who get stuck to understand how properties wrappers work. Besides, Your voice is so soft and your pronunciation is very clear which can mesmerize everyone. I already subscribed your channel.
@CodeWithChris
@CodeWithChris Рік тому
Thank you for the kind words! Time for Chris to make a meditation app and to tell us to breathe, breathe, relax, breathe! @AdrienVillez
@alvarovs89
@alvarovs89 2 роки тому
Amazing, very well explained! thank you Chris!
@CodeWithChris
@CodeWithChris 2 роки тому
You're more than welcome, Alvaro! :) -Arthur
@jamesclavel25
@jamesclavel25 11 місяців тому
New with iOS app development and man, a lot of those property wrappers have been explained here which can easily be understood. Many thanks to you sir! Keep up the great videos - you've helped a lot of beginner devs here.
@CodeWithChris
@CodeWithChris 11 місяців тому
Thank you for the kind words! - Pat
@ninumedia
@ninumedia 2 роки тому
Fantastic and clear explanation, thank you so much!
@CodeWithChris
@CodeWithChris 2 роки тому
This comment made our day. Thank you so much, Nirdhar! :) -Arthur
@40_pravalgautam15
@40_pravalgautam15 6 місяців тому
You made it easy to understand
@semilife
@semilife 2 роки тому
Thanks so much Chris as ever clear. Understand this clearly now.
@CodeWithChris
@CodeWithChris 2 роки тому
Awesome, happy to know that we helped you! :) -Arthur
@TheEmperorXavier
@TheEmperorXavier 6 місяців тому
Your content is amazing
@3VAU
@3VAU 11 місяців тому
Very nice and down to earth ;) thank you!
@ammarmujib
@ammarmujib Рік тому
The video seems to be 1 year old, but still masterpiece to understand data flow/proprty wrappers in SwiftUI. Thanks a lot for such simple and clear explanation.
@CodeWithChris
@CodeWithChris Рік тому
You're welcome! - Pat
@KimbrellBrad
@KimbrellBrad 2 роки тому
This was a very well-done explanation! Your style of walking through each combination of wrappers and properties really cleared up much of my previous "fuzzy" understanding of these property wrappers. Thanks Chris!
@CodeWithChris
@CodeWithChris 2 роки тому
Thanks for your lovely feedback, Madd! Means a lot! -Arthur
@LTNKidd
@LTNKidd Рік тому
Very clear walk through, thanks Chris!
@CodeWithChris
@CodeWithChris Рік тому
Appreciate it, thank you! -Arthur
@akshaykumar-qj2kx
@akshaykumar-qj2kx Рік тому
You are awesome teacher Chris :) Thank you for the valuable information.
@CodeWithChris
@CodeWithChris Рік тому
That means a lot! :) Thank you so much! - Pat
@yshlnhn
@yshlnhn Рік тому
Thanks a lot that makes me understand well about data flow
@CodeWithChris
@CodeWithChris Рік тому
So glad it helped! - Pat
@hakeemdeggs9117
@hakeemdeggs9117 9 місяців тому
Amazing!!!!!!
@uocnguyen5431
@uocnguyen5431 Рік тому
Great Tutorial, thanks for this!
@CodeWithChris
@CodeWithChris Рік тому
You're welcome! - Pat
@jbare777
@jbare777 2 роки тому
Thank you for this video, it was excellent. Liked and favorited!
@CodeWithChris
@CodeWithChris 2 роки тому
Wow, you're just the best. We sincerely appreciate your support! :) -Arthur
@sheetalshinde17
@sheetalshinde17 Рік тому
Thanks!!...Very well explained with example..
@CodeWithChris
@CodeWithChris Рік тому
Glad you liked it - Pat
@himanshukesharwani5333
@himanshukesharwani5333 Рік тому
Sir, this really helps me to understand concepts. Thank you for such a good video :)
@CodeWithChris
@CodeWithChris Рік тому
You're welcome! :) - Pat
@ClintonSiegel
@ClintonSiegel Рік тому
Very helpful! Thank you!
@CodeWithChris
@CodeWithChris Рік тому
Thanks for watching! - Pat
@williamwildsmith5162
@williamwildsmith5162 2 роки тому
Great job Chris!
@CodeWithChris
@CodeWithChris 2 роки тому
Thanks for your kind words, William! -Arthur
@thompsonms9941
@thompsonms9941 7 місяців тому
Good explanation bro ! Thanks !
@CodeWithChris
@CodeWithChris 7 місяців тому
Glad it was helpful! Thanks for watching! - Iñaki
@huyle2838
@huyle2838 2 роки тому
This is an awesome video. I feel so lucky to have access to this youtube channel.
@CodeWithChris
@CodeWithChris 2 роки тому
Indeed! Thanks for learning with us! -Arthur
@michellemorgan6986
@michellemorgan6986 Рік тому
Thank you very much for this informative video! It was definitely very clear and simple, and I now have a better understanding of this topic (which I must admit, I was having a difficult time understanding)
@CodeWithChris
@CodeWithChris Рік тому
This made our day. Thanks for learning with us! -Arthur
@DJFabisLP
@DJFabisLP 2 роки тому
Wow, pretty informative and interesting! Thank you
@CodeWithChris
@CodeWithChris 2 роки тому
Anytime! Thanks for learning with us! :) -Arthur
@ThanhNguyen-jk5tn
@ThanhNguyen-jk5tn 2 роки тому
It's really helpful. Thanks!
@CodeWithChris
@CodeWithChris 2 роки тому
Glad to know, thanks for learning with us! -Arthur
@hugge0948
@hugge0948 Рік тому
Such a good tutorial
@CodeWithChris
@CodeWithChris Рік тому
Thank you so much! Cheers! - Pat
@nojarhead
@nojarhead Рік тому
Hi Chris, thanks for the excellent tutorial. Here's a couple of nuances that I've recently noticed in how @ObservedObject publishes changes and triggers redraws: 1. if your Profile class had a second @Published property that is not used in the layout code, any changes to that property would trigger a redraw of the view anyways. 2. setting the same/current value to a @Published property (e.g. isLoggedIn = true when it's already true) will trigger a redraw of the UI 3. contrary to #2, the .onChange modifier will only react to new values and won't be triggered when setting the same value over and over
@CodeWithChris
@CodeWithChris Рік тому
Thanks for sharing these! - Pat
@kal5211
@kal5211 9 місяців тому
My man 👍
@sathriyansam727
@sathriyansam727 2 роки тому
Wow super you just made my Sunday productive......👍🏻👍🏻🙂
@CodeWithChris
@CodeWithChris 2 роки тому
We're glad that you found us, Sathriyan! :) -Arthur
@petermartins2772
@petermartins2772 9 місяців тому
You're the the best
@gpinto52
@gpinto52 Рік тому
excellent review
@CodeWithChris
@CodeWithChris Рік тому
Thank you so much! - Pat
@alonavall08
@alonavall08 Рік тому
Wow thanks for this video now I understand...
@CodeWithChris
@CodeWithChris Рік тому
You're welcome! - Pat
@weilingwang8331
@weilingwang8331 10 місяців тому
Thanks!
@CodeWithChris
@CodeWithChris 10 місяців тому
No problem! - Pat
@salmahassan8689
@salmahassan8689 2 роки тому
Great Video .. Thanks :)
@CodeWithChris
@CodeWithChris 2 роки тому
You are so welcome, subscribe for more! :) -Arthur
@madoussfofana6045
@madoussfofana6045 Рік тому
Very very very Good explanation. Well done Chris. Tell me where do you collect those information as developper? When I read the Apple document without exemple. it's very hard to understand.
@srome0711
@srome0711 Рік тому
Great video
@CodeWithChris
@CodeWithChris Рік тому
Glad you enjoyed it! - Pat
@dangerwang
@dangerwang 2 роки тому
Wow, this was super helpful Chris, thanks for putting this explanation together. Also, it sounds like you are using a custom mechanical keyboard, or maybe I'm wrong. What keyboard are you using?
@CodeWithChris
@CodeWithChris 2 роки тому
Hi, Kevin! Thanks for your kind support! Kindly send an email to care@codewithchris.com so I can give you more info! The links are too long to share here, haha. :) -Arthur
@SomwangIssaramala
@SomwangIssaramala Рік тому
Thank
@volimpia
@volimpia 2 роки тому
Thank you
@CodeWithChris
@CodeWithChris 2 роки тому
Anytime. Thanks for being here! :) -Arthur
@nijeecooper621
@nijeecooper621 2 роки тому
Hey Chris! Love the videos! I’m new to apps. Anyway you could make a series on how to make a app like Tik tok that let’s the users upload their videos?
@CodeWithChris
@CodeWithChris 2 роки тому
Appreciate your support. Kindly post your idea here: app.productstash.io/codewithchris#/ideas Thank you! -Arthur
@MiChElnumber4
@MiChElnumber4 2 роки тому
Nice explanation Arthur! Is it possible to change an observable object in another class? I have my logic going on in a separate class and would like do make some changes in states viewable in the view file?
@CodeWithChris
@CodeWithChris 2 роки тому
Hello, kindly post your question in our CodeCrew forum so that our tech support staff can assist you. Go here: codecrew.codewithchris.com. Thanks for learning with us! -Arthur
@janstepnicka6553
@janstepnicka6553 9 місяців тому
Hello, thanks for your work. At 17:17 shouldn't the first line be @ObservedObject var myObj = MyObject() ?
@kevinvelasco1715
@kevinvelasco1715 Рік тому
I saw the video, great explanation, but I so simple, I'd like to know what happens if you need more than 1 enviormentObject. For instance, we have a model Company and model User that models are used in many parts of the app what is the correct way to pass 2 enviormentsObject and reuse that 2 models executed one time the user init session.
@CodeWithChris
@CodeWithChris Рік тому
We suggest posting on our CodeCrew forum so that our tech support staff can help you. Just visit this link codecrew.codewithchris.com - Pat
@matthewjura3377
@matthewjura3377 4 місяці тому
still great two years later
@CodeWithChris
@CodeWithChris 4 місяці тому
Glad it was helpful! Thanks for learning with us! - Iñaki
@shroomadelics
@shroomadelics 2 роки тому
Woow such great Tutorials. I already have done the Cardgame App 😊 How do you proceed, if for whatever reason you want to create twice instances of Profile and use it with the property wrapper "EnvironmentObejct"? Would you have to create a constant for each instance (ex.: myProf1 = Profile () ) and then call the two references with the modifier EvnironmentObject? English is not my native language, hope you understood it anyway ^^
@CodeWithChris
@CodeWithChris 2 роки тому
Hello, kindly post your question in our CodeCrew forum so that our technical support staff can assist you. Go here: codecrew.codewithchris.com/ Thank you! -Arthur
@user-vf2qm6ui5r
@user-vf2qm6ui5r 9 місяців тому
I would KILL for you to teach Java, you're leagues better than my college professor.
@CodeWithChris
@CodeWithChris 9 місяців тому
Thanks for watching! I'll be sure to let Chris know :) - Iñaki
@stephaniewagstaff6563
@stephaniewagstaff6563 11 місяців тому
How would I get what the user types in TextField over to another view. I can't seem to get use the property its held in to do so? Thank you.
@rapier64
@rapier64 Рік тому
Hi Chris! I like your tutorials and I learnt a lot. But there is one more thing. I would like to integrate a print function for the AirPrint (SwiftUI). But unfortunately, I couldn't find any tutorials for this topic. Is it possible to integrate a printing function for SwiftUI at all? If yes, where could I find these information/tutorial? Thanks a lot. Peter🙂
@CodeWithChris
@CodeWithChris Рік тому
Hello, kindly post this question in our tech support forum so that our tech support staff can assist you. Go here: codecrew.codewithchris.com. Thank you! -Arthur
@nindz9272
@nindz9272 2 роки тому
A small typo in the slide on ~17:12. It should be "ObservedObject" instead of "ObservableObject" (although you said it correctly :D)
@CodeWithChris
@CodeWithChris 2 роки тому
Oh, thanks for catching that! :) -Arthur
@nagarajvrao7249
@nagarajvrao7249 2 роки тому
Plz include StateObject... In the follow up video
@CodeWithChris
@CodeWithChris 2 роки тому
Thanks for watching! :) -Arthur
@02244
@02244 Рік тому
What if I want to use 2 EnvironmentObjects of the same type? How do I specify the exact name of the variable in the root View?
@CodeWithChris
@CodeWithChris Рік тому
We suggest posting on our CodeCrew forum so that our tech support staff can help you. Just visit this link codecrew.codewithchris.com - Pat
@sabalkatuwal8162
@sabalkatuwal8162 Рік тому
👍
@alinamarrygeorge2630
@alinamarrygeorge2630 2 роки тому
good
@CodeWithChris
@CodeWithChris 2 роки тому
Thanks, Alina! :) -Arthur
@suchcodemuchwow
@suchcodemuchwow Рік тому
How do you reformat the code ?
@CodeWithChris
@CodeWithChris Рік тому
Hi! We suggest posting your question on our CodeCrew forum. Our tech support staff will help you out. Just visit this link codecrew.codewithchris.com - Pat
@rambabuguttula1500
@rambabuguttula1500 2 роки тому
How can download the code with Chris phone or laptop and koputer
@CodeWithChris
@CodeWithChris 2 роки тому
Can you clarify your question? -Arthur
@Wiintb
@Wiintb Рік тому
You do a perfect job. But there is no way I can learn all from you. Need some more structure. Especially missing coredata.
@CodeWithChris
@CodeWithChris Рік тому
You can get started here codewithchris.com/start :) - Pat
@joshuapaulhawthorne
@joshuapaulhawthorne 2 роки тому
What is a “View”
@CodeWithChris
@CodeWithChris 2 роки тому
Hello, thanks for your kind words! Best if you post your question in our CodeCrew forum so that our tech support staff can guide you. Go here: codecrew.codewithchris.com. Thanks for learning with us! -Arthur
@AlynneTheFlorifant
@AlynneTheFlorifant 8 місяців тому
At 17:17 you say @ObservedObject but the slide shows @ObservableObject. But man am I loving these breakdowns. Watching it right before an exam😅
@CodeWithChris
@CodeWithChris 8 місяців тому
🙈🤫 - just to make sure you were paying attention! @AdrienVillez
iOS Core Data QuickStart Tutorial 2020
1:10:58
CodeWithChris
Переглядів 97 тис.
Пескоструйный АППАРАТ! #shorts
01:00
Гараж 54
Переглядів 3,2 млн
What Happens If We Stack Overflow in Linux Kernel
5:35
Nir Lichtman
Переглядів 7 тис.
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
SwiftData Basics in 15 minutes
15:18
CodeWithChris
Переглядів 33 тис.
Has Generative AI Already Peaked? - Computerphile
12:48
Computerphile
Переглядів 25 тис.
SwiftUI Data Flow in iOS 17 - Observation & @Observable
7:57
Sean Allen
Переглядів 38 тис.
Xcode Tutorial - Step by Step for Beginners
56:52
CodeWithChris
Переглядів 305 тис.
New SwiftUI Data Flow with Observation - iOS 17
8:30
iOS Academy
Переглядів 6 тис.