Environment Property Wrapper | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/18176818-your-first-ios-and-swiftui-app-polishing-the-app/lessons/21

In the environment property wrapper lesson, Ray mentions that the link to the available environment properties from the Apple developer website would be posted, but it doesn’t seem to be included in the notes below the video. Just FYI. :slightly_smiling_face:

Looks like this might be it: Apple Developer Documentation

Hi Evan!
Glad someone is paying attention! Thank you for pointing it out — it has now been added to author’s notes below the video :slight_smile:

Where can I find the author notes? I tried looking on the site but I could not find them. Is it the same as the github?

After creating the opacity variable, Ray removed the entire starting opacity value of 0.3 * 0.8. Wouldn’t it be closer to the FIGMA version if we put opacity * 0.8 so that we are adding the group variable, but keeping the starting 80% opacity of the rings?

(It’s not a big difference visually, but I want to make sure for education purposes)

@rossp779 Below each video we have a section where we show any author notes for the video:

@jnubz Good catch! This looks like an oversight on my part (should have been opacity * 0.8 as you pointed out).

1 Like

Awesome. Thank you. Appreciate it

Hi Ray, when I took on the challenge in this video for the rings I decided to use a computed property. so underneath @Environment(.colorScheme) var colorScheme I had put the lines var opacity: Double {
colorScheme == .dark ? 0.1 : 0.3
}

Is there any benefit to your approach over this or does it come to to preference?

@elgordoroura Very cool! Here’s the way I feel about it:

  • For this particular use case, where opacity is only needed in one place, both approaches are equally good (IMHO it comes down to preference/opinion).
  • If you needed to use opacity in two different methods / computed properties, then your method would be better as it would be a good way to avoid repeating code.

Wouldn’t it be much easier to create an alternative color for dark mode in the asset catalogue which uses opacity?
You’re probably showing us this method to introduce a new topic, I’m just wondering if there is any disadvantage to using the asset catalogue.