In this video, I'm going to talk about Observable Objects in SwiftUI and why we require them additionally to @state properties. Let's explore two common usages for observable objects, one for complex logic that requires properties and methods (as a ViewModel) and sharing data across the whole app. The topics described are:
0:52 - Why @State properties aren't enough?
4:47 - Observable Objects
7:37 - Can I use observable objects with @State property wrapper?
10:56 - @StateObject & @ObservedObject
13:31 - ObservableObject example: ViewModel
17:48 - Usage of @Published properties in Observable objects
20:30 - ObservableObject example: User Model across whole app
26:40: - TL;DW: Summary
Also related:
SwiftUI's Stacks: • SwiftUI Intro - Custom Views with St...
SwiftUI's Lists: • SwiftUI Intro - Lists
@State & @Binding properties: • SwiftUI's lifecycle, @State and @Bind...
Source code showed in the video: https://github.com/pitt500/swift-and-...
References:
https://developer.apple.com/documenta...
https://developer.apple.com/documenta...
Don't forget to subscribe to the channel, leave a like ♥️, and follow me on social media:
Twitter: / swiftandtips
Personal: / pitt500
Finally, ask me for a video you would like to see next 😄!
Have a great day! 🎉
PS: I really appreciate your feedback, comments, suggestions for improvement or what video would you like to see next 😉