View models or models often have optionals, which makes it hard to bind them to SwiftUI. I often run into this situation, and usually end up making the respective property a non-optional. However, it's not always possible to do this (for example, if the code is part of an SDK you use). And even if you can change a property to a non-optional, there probably was a reason why it was defined as an optional in the first place.
In this article, Donny shows how to create a custom
Binding that allows us to define a default value for an optional property. Really handy in many situations, and I will definitely be using this in my apps.
Understanding the SwiftUI view lifecycle is essential, especially when interfacing with other parts of your system. Ole wrote an app called SwiftUI View Lifecycle that allows you to observe how different SwiftUI constructs and containers affect a view’s lifecycle, including the lifetime of its state and when onAppear gets called. Great for exploring and developing a deeper understanding of SwiftUI.