This code is something similar to my current UI. I have alot of view in between of Spacer(). I notice that when i add alot of Spacer() i get this error //Trailing closure passed to parameter of type ‘HorizontalAlignment’ that does not accept a closure// why is that?
import SwiftUI
struct Phrases2: View {
var body: some View {
ZStack() {
Text("")
Text("")
VStack() {
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
}
}
}
}
>Solution :
The issue here is the number of views in the stack. ViewBuilder in SwiftUI allows you to have up to 10 views in the HStack/VStack/List.
You can avoid the issue using Groups:
VStack {
Group {
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
}
Group {
Text("")
Spacer()
Text("")
Spacer()
Text("")
Spacer()
}
}