Use PreferenceKey to extract values from child views in SwiftUI | Advanced Learning #10

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

ความคิดเห็น • 67

  • @monstrositylabs
    @monstrositylabs 2 ปีที่แล้ว +3

    You are the only iOS dev I can handle listening to. Everyone else waffles on and sends me to sleep.

  • @RobertHolzapfel
    @RobertHolzapfel 2 ปีที่แล้ว +3

    Lots of tutorials out there focus only on basic stuff, but you, Nick you teach the more advanced stuff. Really appreciate that! Thanks very, very much! Just subscribed to your channel.

  • @cinquain0
    @cinquain0 3 ปีที่แล้ว +8

    This is probably the most confusing lesson I’ve seen so far from Nick. I’ll definitely need to rewatch

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      We’re going to use these in the next 2 videos so you’ll get some practice 🤠

    • @30guarino
      @30guarino 3 ปีที่แล้ว

      I haven't been able to finish it because I catch myself going on autopilot lol

  • @Tzvika-h9d
    @Tzvika-h9d ปีที่แล้ว

    ניק אתה תותח הסברים ממש ברורים
    קצרים וקולעים תודה רבה לך
    ממדינת ישראל !!!!

  • @shadowseekerme
    @shadowseekerme 2 ปีที่แล้ว +2

    No doubt the explanations on each of the series have been magnificent :) and gone inside such easily and fast.

  • @roshanthapa25
    @roshanthapa25 2 ปีที่แล้ว +2

    The whole series is awesome... love how you come up with the use cases for each topic

  • @dev_jeongdaeri
    @dev_jeongdaeri 3 ปีที่แล้ว +2

    your content is like a gold mine!!!

  • @Mahadev-x7u
    @Mahadev-x7u 3 ปีที่แล้ว +3

    Thank you so much Nick... Awesome examples and very powerful tool. Thank you for sharing your knowledge. Keep going . Energy and persistence overcome obstacles.

  • @enriqueavina6827
    @enriqueavina6827 2 ปีที่แล้ว

    Incredible tutorial! The pace & quality is perfect! THANK YOU!

  • @josemanuelortizsanchez4983
    @josemanuelortizsanchez4983 2 ปีที่แล้ว

    Very interesting to be able to customize the behavior of our titles or to be able to know if an object is on the screen or not, how much scroll has been done in the view, etc. Thank you!

  • @ugolafosse3267
    @ugolafosse3267 3 ปีที่แล้ว +1

    Bro you are my favorite teacher by faaar! I would definitively buy a Course from you about building Really Advanced production app using the latest SwiftUI Features (async await sequence complex filtering, MapKit, CoreKit and professional animations just to give you some ideas). In the meantime keep up the excellent work.

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +3

      Thanks Ugo! I definitely want to do a bigger app soon. I'll keep those in mind.

  • @TheSpiralnotizblock
    @TheSpiralnotizblock 2 ปีที่แล้ว

    This is what I needed. Really good examples! Didn't know that this even existet!

  • @anthneyjane1097
    @anthneyjane1097 3 ปีที่แล้ว +4

    as always Nick your the man! would you consider fully using preferencekeys for any communication back to parent, as an alternative for bindings? or is there a performance cost

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +8

      I don’t think there’s much of a performance cost here. Bindings are better if the value will keep changing, while the preference key will be set only once per init. The problem with these PreferenceKeys is that they are environment variables so multiple views could be writing and overwriting to them. You also need to create a custom Key and observe the key for every value you create. I use these sparingly, usually only when I find a Binding isn’t scalable. Well use these in the next 2 videos so you’ll see some real world examples!

  • @priceringo1756
    @priceringo1756 3 ปีที่แล้ว

    Top notch opening and introduction. :)

  • @KimbrellBrad
    @KimbrellBrad 3 ปีที่แล้ว

    Will need some review but this is very powerful! Likely several reviews LOL!

  • @sondoskannous3306
    @sondoskannous3306 2 ปีที่แล้ว

    It's really new information for me. Thanks alot

  • @ovadianyc
    @ovadianyc 3 ปีที่แล้ว +1

    Hey... you are definitely one of the best teachers i have ever encountered . I am having great great difficulty with the Apple Sign in in the instagram course, it seems your method is outdated . I'm trying here because no response in the Q&A section. Can you please do a tut on Firebase apple sign in if possible. Thanks very much for all your efforts.

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      Hi, sorry about that. The DogGram course is a bit deprecated now. I will be covering Firebase on this channel soon!

    • @ovadianyc
      @ovadianyc 3 ปีที่แล้ว

      @@SwiftfulThinking i solved the issue an posted solution in course for anyone else who may have same issue.

  • @ncba
    @ncba 2 ปีที่แล้ว

    5:45 if your value does not update remove the "value = nextValue()". For some reason the initial code stopped working until you remove that.

  • @franklemur5518
    @franklemur5518 2 ปีที่แล้ว +1

    WOW - This is quite confusing. I liked your reply to Ago re using Bindings unless not scaleable. Any reason you wouldn't use the environmental variable technique?

    • @SwiftfulThinking
      @SwiftfulThinking  2 ปีที่แล้ว

      Environments update from parent to child.. this is the reverse, a child view trying to update the parent’s value

  • @magedmohmed4403
    @magedmohmed4403 ปีที่แล้ว

    Thanks a lot nick , you are perfect in explanation

  • @touschflorian1679
    @touschflorian1679 2 ปีที่แล้ว

    Amazing like always. You're a great teacher 🥵

  • @muncho404
    @muncho404 2 ปีที่แล้ว

    Nice work💕

  • @bruhmoment3731
    @bruhmoment3731 2 ปีที่แล้ว

    Very well explained! Thank you!

  • @tmjromao
    @tmjromao 3 ปีที่แล้ว +1

    Hi Nick, learning a lot with your videos. You explain very well and most important put yourself on the beginner shoes. A doubt about PreferenceKey, is it possible to have more than 1 key? e.g. implement all the three use cases you explain on a single app? many thanks, best regards

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +3

      Glad to hear that Tiago! Yes, you can create as many PreferenceKeys as you want in your app. I often will have 1 for SafeArea, 1 for ScrollViewOffset, and maybe 1 for reading location of an object. The thing to keep in mind is that when setting the values for the PreferenceKey, it overwrites the previous value. So generally, you justdon't want two different functions on the same screen to be updating the same PreferenceKey. (I hope that make sense? lol)

    • @tmjromao
      @tmjromao 3 ปีที่แล้ว +1

      @@SwiftfulThinking it doesn't (yet, lol) but thanks for the reminder. It would be good if you could do/show how to do an app with all these things you explain, i.e. another todo app :)

  • @AkbarshahJumanazarov
    @AkbarshahJumanazarov หลายเดือนก่อน

    Good explanation!

  • @kavinda_dilshan_paramsoodi
    @kavinda_dilshan_paramsoodi 2 ปีที่แล้ว

    Loved it... 😍

  • @nalinporwal1446
    @nalinporwal1446 ปีที่แล้ว

    Bro I love you. You teach me like Hell... ❣

  • @rajinderpaul1978
    @rajinderpaul1978 2 หลายเดือนก่อน

    Awesome content!!!!

  • @emadisaac7052
    @emadisaac7052 ปีที่แล้ว

    can I use PreferenceKey to set the height of TabView according to the content of it's Childs , because if I put tabView in ScrollView I have to specify the height of the tabview otherwise the tabview will not appear

  • @OBLIVIOUSKARI
    @OBLIVIOUSKARI ปีที่แล้ว

    This video was amazing thank you

  • @LM-bn1wt
    @LM-bn1wt ปีที่แล้ว

    Very good but it is very difficult to retype everything on Xcode when we want to experiment with that. Please make the projects available for your videos! Thanks

  • @mylaluna
    @mylaluna ปีที่แล้ว

    Thank you for the tutorial.

  • @LM-bn1wt
    @LM-bn1wt ปีที่แล้ว

    Related to this preferenceKey... isn't easier to create a @State variable in the parent and pass a binding to the children? I agree that if you have 3 child views, one inside another, the preferenceKey will be "easier"

  • @TrueMomentsVelogs
    @TrueMomentsVelogs ปีที่แล้ว

    if we want to use Background again to assign another background , what will happen?

  • @jemmytech5474
    @jemmytech5474 2 ปีที่แล้ว

    Why Does SwiftUI ScrollView Return To Top but not to the point from where I started/clicked? can I control this with the prefernceKey or geometry reader?

    • @vladimirmoor
      @vladimirmoor 2 ปีที่แล้ว +1

      You can use ScrollView Reader - there is some lesson in this course here.

    • @jemmytech5474
      @jemmytech5474 2 ปีที่แล้ว

      @@vladimirmoor please link me there

    • @vladimirmoor
      @vladimirmoor 2 ปีที่แล้ว

      @@jemmytech5474 th-cam.com/video/ZkOvD3okAJo/w-d-xo.html

  • @anubhavjain739
    @anubhavjain739 4 หลายเดือนก่อน

    Awesome video

  • @karljay7473
    @karljay7473 3 ปีที่แล้ว

    Thanks for the tutorials, do you have a link to the code?

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

      Hi Karl, the code will be posted on my Github once I finish recording the playlist (about 1 week from now) github.com/SwiftfulThinking

  • @TrueMomentsVelogs
    @TrueMomentsVelogs ปีที่แล้ว

    why is it static?

  • @刘小杰-d9b
    @刘小杰-d9b 2 ปีที่แล้ว

    Why can not I use state/binding simply?

  • @ncba
    @ncba 3 ปีที่แล้ว

    15:25 thats one funny solution 😆 I dont know why I laughed

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว

      😅

    • @ncba
      @ncba 3 ปีที่แล้ว

      @@SwiftfulThinking thanks for the detailed tutorial, opened up some pretty neat features for my app

  • @ישראלברזין
    @ישראלברזין 3 ปีที่แล้ว +1

    can you share code please?

    • @SwiftfulThinking
      @SwiftfulThinking  3 ปีที่แล้ว +1

      All source code is posted to my github! github.com/SwiftfulThinking

  • @vitolom6578
    @vitolom6578 3 ปีที่แล้ว +1

    Hey then discord group?

  • @paulancajima
    @paulancajima 2 ปีที่แล้ว

    thank you