I'll take a crack at it, though I'm not 100% sure I'm right.
So, EnvironmentValues
is basically holding a Dictionary of values that are part of the "Environment". You can get an idea of what Dictionary values are included in the "Environment" dictionary by default on this page
But in this example, you are trying to add your own custom-made dictionary entry to be included in EnvironmentValues
, even though it isn't there by default. So, you are defining what what will happen when you get
and set
the value of this new dictionary entry that you are creating.
when you get the value of it...
get { self[MyEnvironmentKey.self] }
The first self
refers to the EnvironmentValues
Dictionary, and the MyEnvironmentKey.self
refers to the name of the key that you have created.
So, it is basically saying, "When I look in the EnvironmentValues
dictionary for the key myEnvironmentKey
, tell me what is stored as the value there."
As an example, if you created a Dictionary like this...
var animals: [String: String] = ["cat": "furry feline", "dog": "furry canine"]
you could get the value of the "cat" key by using this...
animals["cat"]
and it would return
"furry feline"
but in your example, you are basically just using
EnvironmentValues[myEnvironmentKey]
instead of
animals["cat"]