Swift View Modifiers

How is a view modifier able to have a method as a parameter argument? In the following code, .blue is listed as an argument all by itself within the .foregroundColor parentheses. The same is true for .title as an argument within the .font view modifier. I didn’t realize that methods could be listed by themselves as an argument when using dot notation. Could someone help me understand this better? Feeling a little confused.

Text("Hello, World!")


I believe this is a feature of the Swift language called Implicit Member Expression (docs here).
It’s a syntax feature that can be used to access type members in those places where Swift can determine the implied type from the context.

In order to understand how this works, it helps to look at the documentation for Text.font() (here) and Text.foregroundColor() (here).

As you can see from the documentation, Text.font() takes an argument with an optional type of Font and Text.foregroundColor() takes an argument with an optional type of Color. These will be the implied types inside the methods if implicit member expression is used.

Blue is one of the standard colors, usually accessed via Color.blue, and title is one of the standard fonts typically accessed though its type via Font.title. Because of implicit member expressions, these can be accessed using the shortened .blue and .title inside of Text.foregroundColor and Text.font, because Swift can tell infer what the type is for each of them based on the context. However, if it’s easier for you to read/understand, you can always always just pass in the full Color.blue or Font.title, which will work exactly the same.

Hopefully this explanation helps clear up some of the confusion!

Is this because Color and Font are special enum types and whatever comes after the dot is a member?