SwiftUI Data Flow in iOS 17 - Observation & @Observable

Поділитися
Вставка
  • Опубліковано 27 лис 2024

КОМЕНТАРІ •

  • @seanallen
    @seanallen  Рік тому +3

    My iOS Dev Courses (SwiftUI & UIKit) - seanallen.teachable.com

  • @WestCoastAce27
    @WestCoastAce27 Рік тому +11

    This video made me think how far Xcode has come; from the days of coding everything in Objective-C, to the early days of storyboards, Simulator sometimes catching all the issues with an app before actually testing on a physical device. Apple has really hit their stride with Swift and SwiftUI.

  • @FloWritesCode
    @FloWritesCode Рік тому +29

    While these changes might be a bit confusing for us "veteran developers", I believe this new syntax is much nicer than before.

    • @seanallen
      @seanallen  Рік тому +2

      It will take a bit to get used to, but I agree. This is much better.

    • @Spacer-l3j
      @Spacer-l3j 10 місяців тому

      how exactly is this confusing since it just eliminates unnecessary and doesn't add any extra code?

    • @АртемВласенко-щ5п
      @АртемВласенко-щ5п 9 місяців тому

      I see problem here about we have to set init values, Prefer constants way

  • @ryankanno2562
    @ryankanno2562 Рік тому +4

    Very good update! Thanks for sharing!
    I hope SwiftUI will let us use the .toolbar modifier without needing a NavigationView sometime soon.

  • @chesterman18g
    @chesterman18g Рік тому +2

    Swift - constant improvements. It's nice to see that the language is evolving and so alive.

    • @seanallen
      @seanallen  Рік тому +1

      It's a gift and a curse. I agree, it's nice to see it evolving and improving. But stability is also valuable.

  • @gmikay
    @gmikay Рік тому +13

    I hope SwiftUI will become stable in my lifetime

    • @seanallen
      @seanallen  Рік тому +2

      This is fair.

    • @AndyJMacLeod
      @AndyJMacLeod Рік тому

      Swift is developing quickly! And it will be around for a generation…

  • @donathmm3881
    @donathmm3881 Рік тому +4

    Great Video of the new SwiftUI update Sean! Thank you so much. Keep going 🎉 I need such videos because they are short and explain core changes as I'm so busy 😂

    • @seanallen
      @seanallen  Рік тому +1

      Thanks Donat! That's why I make them. A lot of people don't have time to study the WWDC videos so I make short and to the point summaries.

  • @twizzlestix9309
    @twizzlestix9309 Рік тому +2

    Wow this just made my life easier as I’m learning SwiftUI and building an app for the first time.

    • @seanallen
      @seanallen  Рік тому

      Glad it helped!

    • @vladimystfleur8295
      @vladimystfleur8295 Рік тому +1

      I am new to programming as well, and this whole @StateObject and @ObservableObject was confusing to me. I don’t know how many articles I’ve read and videos I’ve watched. But that seems simpler. I am heading back to the drawing board.

  • @twizzlestix9309
    @twizzlestix9309 5 місяців тому

    Thanks Sean. Always informative and with good examples and to the point. Best watched caffeinated ☕️ 😬

  • @dann_beau
    @dann_beau Рік тому +7

    Any thoughts on how the new changes with @Observation will affect using ViewModels or reinforce not using ViewModels? I think it will depend, but I think it would be great to see how @Observation would impact one of your more involved MVVM projects.
    Also, love your videos, thanks for all the content!

    • @seanallen
      @seanallen  Рік тому +2

      I don't think this will have any affect on the view models vs. no view models debate. The way I see it, it's just a cleaner, more performant way to do something we've already been doing. It's not a fundamental ideological change on updating the UI.

  • @vladimystfleur8295
    @vladimystfleur8295 Рік тому

    Thank you for this video Sean! That’s going to help a bunch

  • @AlexanderWebster_
    @AlexanderWebster_ 6 місяців тому +1

    Yoooo. This was so confusing when I learned it at first. So nice you can just give a class this property wrapper now! So clean.

  • @ToddHoff
    @ToddHoff Рік тому +1

    Nicely explained-as usual.

  • @danuff
    @danuff Рік тому +2

    OH MY GOD, THANK YOU for this video. I was doing everything BUT importing Observation (is it in the docs or a WWDC video?)

    • @seanallen
      @seanallen  Рік тому +1

      It's in the Docs, but in the WWDC video they import Swift Data (which imports Observation)

  • @ryshask
    @ryshask Рік тому +2

    Looks like this is more for observing an existing object... I would keep the older syntax for clarity... I don't agree it's more readable.... It obfuscates the use of that variable in your swiftUI view.... Forcing you to check through the view as to it's use.. That is to say "Is this observable?"... You clearly know if you have a @stateObject declaration... Very cool that you can see what the macro's are doing.... that's a killer feature. Also if performance is actually improved... That's kind of regrettable having to chose between more verbose syntax and faster execution.

    • @seanallen
      @seanallen  Рік тому

      I see your point about readability and not being sure if your variable on the view is being observed. You kinda just have to "know" that object is marked @Observable - and that could be confusing. Especially in a large codebase with a larger team.

    • @ryshask
      @ryshask Рік тому +1

      @@seanallen yeah exactly... In the quest for cleanliness we lose some things... Of course.. as devil's advocate... One should avoid larger views entirely as the compiler will do the heavy lifting of code optimization... I do like how much work is being put into swift[UI] to improve it's usefulness. Keep up the great videos!

  • @brandonhopkins3438
    @brandonhopkins3438 Рік тому +1

    Beautifully explained!

  • @lukaszc.1653
    @lukaszc.1653 Рік тому +1

    Looks good at first, but how do I react to changes in my business logic? Let’s say the filter changes and I want to run a REST call or execute any other business logic.

  • @alejmc
    @alejmc Рік тому +1

    These changes and the whole SwiftData overhaul makes me want to wait for all of it to get out of beta.
    Thankfully until now it seems that it won’t be forced to macOS Sonoma right? That risk I won’t take for sure short term release.

  • @Joshtrick
    @Joshtrick Рік тому +1

    Thinks for sharing!
    Can you help to explain a bit more about adding @State against no wrapper at all when declaring an @Observable class variable in a view?

  • @SimonJustesen
    @SimonJustesen Рік тому +1

    Nice, I like the cleaner syntax. Do these features ever get backported to older iOS versions?
    I'm building a new app, which is currently targeting iOS 15 (I think it was... )

    • @gmikay
      @gmikay Рік тому +1

      No, its iOS 17+ now

    • @SimonJustesen
      @SimonJustesen Рік тому +1

      @@gmikay Great, thanks - I'll stick to the old method for now then :)

  • @JDAndNightrain
    @JDAndNightrain Рік тому +1

    When I was learning SwiftUI last year, a lot of articles would say to prefer structs over classes. With iOS 17 and the new @Observable macro, does this represent a shift away from preferring structs over classes and instead choosing classes for view models, all else being equal?

    • @seanallen
      @seanallen  Рік тому

      structs over classes is good advice, but not absolute. Classes are necessary for a lot of model objects (even before this change). The new Observation framework and @Observable changes nothing in that regard.

  • @blakesheppard8304
    @blakesheppard8304 Рік тому +2

    when you selected all the @Published text at once how did you do that? what do you have to hold / tap on the keyboard? that's cool

    • @blakesheppard8304
      @blakesheppard8304 Рік тому +1

      found it, you hold the option key

    • @dehrens
      @dehrens Рік тому +1

      Thanks, wondered the same thing xD

  • @AkimboFennec
    @AkimboFennec 8 днів тому

    One question: the old way uses combine, so that you can subscribe to the @Published properties even from other classes. But this new observable macro doesn’t seem to have this Combine functionality of publishers and subscribers, but it is crucial in many applications. Does this new observable have some combine support or what? I am confused

  • @developerios6096
    @developerios6096 Рік тому

    There would be no way with this approach to avoid tracking one or more attributes of a class as you mentioned. Although new syntax is arguably cleaner, we are losing a functionality from previous ObservableObject way to go… i d add a @notupdatable like macro to attributes i dont need to update in the ui, or something like that, or just stick to ObservableObject. Thank you for pointing out this new feature !

  • @jasmanarora9713
    @jasmanarora9713 Рік тому +1

    Your videos are awesome! Can you do a video on SwiftData as well and how it compares to CoreData?

    • @seanallen
      @seanallen  Рік тому +1

      Thanks. That video is coming in a few weeks. I haven't started wrapping my head around SwiftData yet.

    • @jasmanarora9713
      @jasmanarora9713 Рік тому +1

      @@seanallen As long as it is coming in the future, it makes me happy!!!

  • @TheMcGloneCode
    @TheMcGloneCode 4 місяці тому

    Is there a way to use @Observable as an EnvironmentObject?

  • @michaellatta
    @michaellatta Рік тому +1

    I think you still need @State for data that is owned by the view and not provided from the outside.

  • @kp8752
    @kp8752 Рік тому +1

    Any word on when Swift Playgrounds is getting iOS 17 support?

  • @a.h.m1365
    @a.h.m1365 Рік тому +3

    How about the $ sign? do we need it in TextField or other Two way Binding?

    • @seanallen
      @seanallen  Рік тому +1

      This video doesn't address Bindings and the new @Bindable. It is focused on @Observable. But, yes... the way Bindings are handled has changed a bit if you are using the new @Observable. I have a video on that planned.

    • @manwithllama
      @manwithllama Рік тому

      @@seanallen Do you happen to have a mailing list? I'd love to know when you release this new @Bindable video, as you've explained @Observable so well (newbie here). Or best to just check back here?

    • @seanallen
      @seanallen  Рік тому +1

      I don't have a mailing list, so it's best to check back here from time to time (or subscribe)

  • @muradjam
    @muradjam Рік тому

    Thanks for the excellent video. 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 ?

  • @JasonMitchellAZ
    @JasonMitchellAZ Рік тому +1

    Nice and clean

  • @Meekismwisdom
    @Meekismwisdom Рік тому

    I don't see the WWDC link in the description box. How can I get that?

    • @seanallen
      @seanallen  Рік тому

      I'll make sure to add it. But here it is - developer.apple.com/videos/play/wwdc2023/10149/

  • @fayherinn
    @fayherinn Рік тому

    What’s the difference between using @Published and the attribute .onchange with the same var ?? With onchange I can also apply update to the UI only when there is need to

  • @milanlabus1582
    @milanlabus1582 6 місяців тому

    Sean how do you use @MainActor with thses new way i keep getting errors when i try to put an Observable on the main queue, this didnt happen before

  • @sghsri
    @sghsri Рік тому +1

    So basically you don’t need to mark @State for reference types in views as long as the type itself is marked @Observable? I kinda wish it was uniform in requiring @State for value and reference types hmm

    • @seanallen
      @seanallen  Рік тому

      @State isn't changing. It works exactly the same. You no longer need @StateObject (or @ObservedObject) when using @Observable.

  • @carlosvalenzuela7349
    @carlosvalenzuela7349 Рік тому +1

    Is it only possible to use it on iOS 17? Isn't it possible for previous versions?

    • @이윤서-i5w
      @이윤서-i5w 4 місяці тому

      it is iOS 17 API so yeah, can't use for under 17

  • @justmytraining4190
    @justmytraining4190 4 місяці тому

    03:02
    how did you highlight and delete like that?

  • @AkimboFennec
    @AkimboFennec Рік тому

    Sean, may you please tell me one thing. If i want to start creating apps that target IOS17 and above only, so no need to support legacy code, can i use Swiftui for highly customizable app? The things i want to customize are, custom layouts of any imagination i can think of, complex navigation like uikit, customizing tab bar, navigation bar and so forth. Can swiftui accomplish all of this ?

    • @seanallen
      @seanallen  Рік тому

      SwiftUI can accomplish that, but you'd be fighting against the framework. The strength of SwiftUI is the ease of using Apple's components. If you want to customize every little thing, then UIKit is probably the correct framework to go with.

    • @AkimboFennec
      @AkimboFennec Рік тому

      @@seanallen but it is possible right? Just composing custom stuff with simpler built in SwiftUI views? Also, if I plan to target iOS 17 and above, then I don’t need UIKit right? SwiftUI has me covered?

    • @seanallen
      @seanallen  Рік тому +1

      It is possible, yes

  • @rodgetech
    @rodgetech Рік тому +1

    how cool is that :)

  • @FelipeCampelo0
    @FelipeCampelo0 Рік тому

    3:02 how did he select a box like this? A keyboard shortcut?

  • @blytte
    @blytte Рік тому

    how did you select the published with the mouse and deleted it?

    • @seanallen
      @seanallen  Рік тому

      It's vertical selection in Xcode. I have a UA-cam Short about it here - ua-cam.com/users/shorts6mWo5XHkEWo?feature=share

  • @ammarahmad9004
    @ammarahmad9004 Рік тому

    No more Preference and Environment keys.

  • @gandaszn
    @gandaszn Рік тому

    how did you select the code like in 3:00?

  • @marcinfrydrych5319
    @marcinfrydrych5319 Рік тому

    Sadly, it works only on ios 17 apps.

  • @AnthonyBullard
    @AnthonyBullard Рік тому

    SolidJS is bringing the magic of signals everywhere

  • @danvilela
    @danvilela Рік тому +1

    Oh boy. If only Swift worked outside Apple :/

    • @bobweiram6321
      @bobweiram6321 Рік тому

      .NET has a superior broadcast model.

    • @georgebarlowr
      @georgebarlowr Рік тому

      I assume you're referring to SwiftUI not Swift, Swift is an open source project that can be used on various other operating systems and for other needs.

    • @danvilela
      @danvilela Рік тому

      @@georgebarlowr yes and no. I wish we could develop websites with swift ui for example, but even if swift is open source, most people doesn’t use it outside apple, and we need a community for a tech to get traction. Would be cool to be used as node is for example by companies

    • @danvilela
      @danvilela Рік тому

      @@bobweiram6321 not my thing. I did program a little bit of C# in the past though. Not bad, not great either.

    • @bobweiram6321
      @bobweiram6321 Рік тому

      @@danvilela Swift e un lingua muito complicado e mal desiniado!

  • @mishag3027
    @mishag3027 Рік тому

    And again, iOS 17, maybe in 2-3 years we will be able to use it. But knowing Apple, after this time, they can deprecate this API 🤦‍♂

  • @mrmillburnt
    @mrmillburnt 6 місяців тому

    too stringent.. try coding with chris