Group Group Group Group Group Group Group Group Group

How to understand environment property

Hello, in chapter 9 I understand how to extract environmentObject from environment but at page 260 I can not understand how to use environment property like sample code:

@Environment(.verticalSizeClass) car verticalSizeClass.

The correct declaration is

@Environment(\.verticalSizeClass) var verticalSizeClass

and you need to pass a key path to the @Environment attribute - in the case above, it’s the key path to the vertical size class.

Once you’ve added that property, it will always contain the vertical size class, but, most importantly, it will trigger a re-rendering if it changes, which usually happens when you change the device orientation.

Since in the code it’s used to specify a different implementation depending on its value, the result is that the view will rendered differently depending on the value of the vertical size class.

Is there anything specific which is not clear to you? Let me know please.