@Environment in SwiftUI - What is it? How to use it? (2020)

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ต.ค. 2024
  • In this tutorial we will explore what the Environment in SwiftUI is and how we can take advantage of it.
    Learn more about the difference between @Environment and @EnvironmentObject:
    • @EnvironmentObject in ...

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

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

    Very useful! Gives a nice understanding of Environment variables. Thank you!

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

    Great explanation, thank you!

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

    Hey nice video - can you think of an example where it would be useful to implement something like this? It seems quite powerful but practically I can't think of a use case. E.g. in this example just passing in the actual size you want seems more readable. What are the advantages of doing it this way? Maybe if you have many ChildViews and want to keep the size flexible across the app without having to pass it in to each one?
    Thanks - am enjoying your channel!

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 ปีที่แล้ว +5

      Hi James, that’s a great question. In practice I could imagine it for sth. like a theme setting that you want to pass to multiple children views without having to pass it through each of their initializers. Also themes are usually represented by enums or structs which are value types and cannot conform to ObservableObject. So you may consider using @environment if a view is dependent on a type that cannot conform to observableObject.

  • @CraigSchubert
    @CraigSchubert 4 ปีที่แล้ว +1

    Cool stuff! Didn't completely understand it on the first watching, but things like keypaths are still pretty new to me.

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

      Awesome! Thanks for your feedback, I think the concept of key paths is definitely worth a separate video. I will try to explain it a bit more in depth there.

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

      @@BeyondOnesAndZeros am also waiting for it.

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

      @@kasirajan2289 I uploaded a video not long ago regarding Keypaths, please have a look: th-cam.com/video/YY7SlOklZzk/w-d-xo.html

  • @elyesbensalah1904
    @elyesbensalah1904 4 ปีที่แล้ว

    Nice, great explanation and easy sample to understand the fundamentals , excited to see more videos.

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

    Great work!

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

    Excellent lessons in your channel.... Thank you

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

    Thanks a lot !

  • @sipanhazim4128
    @sipanhazim4128 4 ปีที่แล้ว +1

    very helpful thank you
    😍

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

    🤨