@Observable @Bindable: MVVM in iOS 17

Поделиться
HTML-код
  • Опубликовано: 13 окт 2024
  • 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: apple.co/3iFcjjW
    📚 Try CWC+: bit.ly/cwc_flo
    ☕️ Buy me a coffee: ko-fi.com/flow...
    👋 Links: flowritesco.de
    🛠 Forge: apple.co/3riG8MQ
    Affiliate Links ❤
    📕 SwiftUI & Combine Books: www.bigmountai...
    🔬 Get Reports about your apps: appfigures.com...
    📊 Privacy focused analytics: dashboard.tele...
    💻 The most powerful mac app for developers: devutils.app/?...
    ☕️ Support me: ko-fi.com/flow...
    If you have any video suggestions please feel free to let me know by a comment.
    Get in contact via
    Twitter: / flowritescode

Комментарии • 36

  • @FloWritesCode
    @FloWritesCode  Год назад +3

    What do you want to learn more about next?

    • @collocheru
      @collocheru Год назад +1

      Hey Flo, you have an idea if SwiftData be affected by threading like CoreData was?

    • @tiIIus
      @tiIIus Год назад +2

      StoreKit 2 improvements and SF Symbol animations, please🙏

    • @FloWritesCode
      @FloWritesCode  Год назад

      @@collocheru I don't know, but with @.MainActor I would guess that everything has to be on the main thread. Only testing will show :D

    • @FloWritesCode
      @FloWritesCode  Год назад

      @@tiIIus Got it! Both are on my list already :D

    • @tiIIus
      @tiIIus Год назад +1

      @@FloWritesCode Nice!

  • @valeriodalessio191
    @valeriodalessio191 11 месяцев назад +6

    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.

    • @FloWritesCode
      @FloWritesCode  11 месяцев назад +1

      Yup, that works! I recorded this video the day of WWDC23, so nobody really knew how these things worked :D

  • @jeyhey5320
    @jeyhey5320 Год назад +3

    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).

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Thank you. This video was made right when Observation was presented, so it was just a first idea on how the new macros could be used. I will work on a more comprehensive video once Xcode 15 RC is available.

    • @jeyhey5320
      @jeyhey5320 Год назад +1

      @@FloWritesCode I'm looking forward to your new video!

  • @mattheaney729
    @mattheaney729 Год назад +2

    Another great video!
    @Bindable being from SwiftData feels so strange 🤔
    Looking forward to more of your videos! 👏

  • @holgerflick
    @holgerflick Год назад +2

    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.

    • @FloWritesCode
      @FloWritesCode  Год назад

      Thanks for the feedback, I already massively reduced the amount of camera movement in the two most recent videos (not this one).

  • @jamesonwilliams
    @jamesonwilliams 11 месяцев назад +1

    I think you want to do "import Observation" instead of "import SwiftData"

    • @FloWritesCode
      @FloWritesCode  11 месяцев назад

      Yup, that works! I recorded this video the day of WWDC23, so nobody really knew how these things worked :D

  • @danstoian7721
    @danstoian7721 Год назад +1

    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?

    • @tiIIus
      @tiIIus Год назад

      @Bindable is part of SwiftUI. You don't need to import anything else to use it.

  • @dfrankcom
    @dfrankcom Год назад +8

    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.

  • @Visionist
    @Visionist Год назад +1

    Make the font bigger in your future videos. Abit hard to see the code.

  • @artsnstyles
    @artsnstyles 8 месяцев назад

    Isnt "import Observation" enough?

  • @futuristudios
    @futuristudios Год назад

    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?

    • @FloWritesCode
      @FloWritesCode  Год назад

      For sure. There hasn't been a single sample code by Apple that uses anything other than Views and Models. And given that they only release (big) updates with new iOS versions they can always use the latest technologies without having to worry about backwards support.

  • @muradjam
    @muradjam Год назад

    Excellent video thank you. However, My SwiftUI app have this design pattern:
    view 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 ?

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      I don't think there's a "best practice" with the Observation framework yet. Personally I don't use ViewModels with it, but that just means that I can't really say anything about how that would work. I'm sure you can keep the same setup you already have and just change StateObject to State and Binding to Bindable. Then you can also get rid of ObservedObject (in favour of @Model) and @Published.

    • @muradjam
      @muradjam Год назад

      @@FloWritesCode yeah thanks for the reply, as a side note there a wrapper called @ObservationIgnored to opt out observation for model properties that don’t need to be observed

  • @rtorcato
    @rtorcato Год назад +1

    Are we able to play with vision kit preview in Xcode beta?

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Not yet! It's said to be released "later this month". But from the keynote we already have a pretty good idea of how it works (see my posts on Twitter for a detailed breakdown)

  • @Meta273
    @Meta273 Год назад +2

    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

  • @indiekiduk
    @indiekiduk Год назад

    That's called a model not a view model though

    • @yourbestsail
      @yourbestsail Год назад +3

      In my understanding that is a ViewModel, as long is the one in charge of directly updating the View.