in

@Observable @Bindable: MVVM in iOS 17



SwiftUI has once again had significant changes, so let’s have a quick look at how MVVM works in iOS 17 using the new Swift Macro @Observable and the new Property Wrapper @Bindable

πŸš€ LaunchBuddy:
πŸ“š Try CWC+: https://bit.ly/cwc_flo
β˜•οΈ Buy me a coffee: https://ko-fi.com/flowritescode

πŸ‘‹ Links: https://flowritesco.de
πŸ›  Forge: https://apple.co/3riG8MQ

Affiliate Links ❀

πŸ“• SwiftUI & Combine Books: https://www.bigmountainstudio.com/a/tpgmp
πŸ”¬ Get Reports about your apps: https://appfigures.com/r/5by3g
πŸ“Š Privacy focused analytics: https://dashboard.telemetrydeck.com/registration/organization?referralCode=27AOWO4R1TTEJBST
πŸ’» The most powerful mac app for developers: https://devutils.app/?ref=flo
β˜•οΈ Support me: https://ko-fi.com/flowritescode

If you have any video suggestions please feel free to let me know by a comment.
Get in contact via
Twitter: https://twitter.com/FloWritesCode

Share this:

15 Comments

  1. It is not part of SwiftData but it’s part of Observation Framework. It does work if you import SwiftData since SwiftData is also using the Observation framework behind the scene.

  2. This video does not show how to correctly use the new annotations:
    – use '@State var model: ViewModel()' in DummyView because the view owns the model. You can omit the '@State' only when your view does not own the observable, e.g. when it was passed to it by another view.
    – the use of '@Bindable' is only necessary when the view does not own the model, because you would then not annotate it with '@State' and the compiler would not know that it is an observable that can be mutated by the view (although it could theoretically infer it).

  3. Excellent video thank you. However, My SwiftUI app have this design pattern:
    view <- view model -> model
    the view model has @Published and non published properties along with business and helper methods that support the view, the model doesn't have @Published properties, now if I want to adopt the new @Observable macro, is it a best practice to take off the "view model" and migrate all of its business logic into the model itself ?

  4. I really like your videos, but I get motion sick very quickly and the frequent panning makes me dizzy… Maybe just use a bigger font and keep the simulator visible all the time? So my number one suggestion: Less panning and zooming.

  5. do you think this means that apple is shifting away from swiftui/mvvm to using swift data in its place? similar to how you ( and others that i’ve noticed) opted to use core data previously?

  6. i like your video, but please stop this zoom in zoom out effect. it creates kinda flimsy feeling xD way too often, because most times nothing happened in the sim. greetings

  7. Thanks for the video; very fast! Instead of importing SwiftData you can import Observation to gain access to the @Observable macro and @Bindable property wrapper.

  8. Dude, you're really fast! πŸ˜…
    Thanks, this is great!
    Not sure why @Bindable is part of Data🧐
    Since it's used to have bindings now, is that not part of SwiftUI? Do I miss something?