Items followed by parentheses ()
are generally UI elements in SwiftUI, like Text
or Picker
.
Items followed by curly brackets {}
are generally container elements, like VStack
or HStack
. These usually do not show up on screen but instead encapsulate other elements and group them together.
Items preceded by a period .
are generally modifiers that are applied to one of the above and alter or specialize it in some way.
So, in code like this:
VStack {
Text("Hello world")
.font(.headline)
}
VStack
is a container that has one Text
element inside it. That Text
element has a font
modifier applied to it to give it the headline
style.
You can also have parentheses ()
on containers, in which case they apply some kind of parameters to adjust the characteristics of the container, like so:
VStack(alignment: .top) {
//...some elements in here
}
And some UI elements can contain other UI elements, in which case they will be followed by curly brackets {}
:
Picker("Flavor", selection: $selectedFlavor) {
Text("Chocolate").tag(Flavor.chocolate)
Text("Vanilla").tag(Flavor.vanilla)
Text("Strawberry").tag(Flavor.strawberry)
}
Hope this makes sense.