-1

I have a sccreen on my witch only displays text but when i try to add more than 10 views inside my Group View i'm getting this error. I tried to wrap the VStack with the Group View but nothing changed

Extra argument in call

My code:

struct GoalTipsView: View {
    
    var body: some View {
        
        NavigationView {
            
            ScrollView {
                
                VStack(alignment: .leading) {
                    
                    Group {
                        
                        HStack(spacing: 5) {
                            Text("Using the")
                            Text("Smart").bold()
                            Text("format is important for")
                            Spacer()
                        }.padding(.leading, 7)
                        
                        HStack(spacing: 5) {
                            Text("structuring goals correctly and increases the")
                        }.padding(.leading, 7)
                        
                        HStack(spacing: 5) {
                            Text("chance of success").bold()
                        }.padding(.leading, 7)
                        .padding(.bottom, 35)
                        
                        HStack(spacing: 5) {
                            Text("SPECIFIC").bold().font(.system(size: 23))
                        }.padding(.leading, 10)
                        
                        HStack(spacing: 5) {
                            Text("(Goals that are simple, sensible, significant.) \n A specific goal allows you to focus on a clear and specific target. It can help you visualise the desired outcome and makes it easier to track your progress. Focusing the mind on the desired goals is important for success. Every word needs to be useful and necessary in the goal sentence.").padding(5)
                        }.padding(.leading, 7)
                        
                        HStack(spacing: 5) {
                            Text("MEASURABLE").bold().font(.system(size: 23))
                        }.padding(.leading, 10)
                        .padding(.top, 23)
                        
                        HStack(spacing: 5) {
                            Text("(goals that are meaningful, motivating.) \n If your goal isn't measurable, there will be no way to determine if it\'s achieved. Work out the criteria for measuring progress towards the achievement of the goal. \n When the goal is measured you, are much more likely to keep on track, reach milestones, and experience the achievement that is needed for continued effort required to reach the goal.").padding(5)
                        }.padding(.leading, 10)
                        
                        
                        HStack(spacing: 5) {
                            Text("To assist with making the goal measurable:").bold().font(.system(size: 18))
                        }.padding(.leading, 10)
                        .padding(.top, 20)
                        
                        
                        HStack(spacing: 5) {
                            Text("How will i know when it is accomplished? \n What exactly needs to happened to consider this goal achieved?").padding(5)
                            Spacer()
                        }
                        
                        
                        HStack(spacing: 5) {
                            Text("ASSIGNABLE/ACTION-ORIENTED").bold().font(.system(size: 23))
                        }.padding(.leading, 10)
                        .padding(.top, 23)
                        
                        
                        HStack(spacing: 5) {} // Extra argument in call
                        
                        
                    }
                    
                }.padding(.top, 10)
                
            }.navigationBarHidden(true)
            
        }
        
    }
}

struct GoalTipsView_Previews: PreviewProvider {
    static var previews: some View {
        GoalTipsView()
    }
}
GSepetadelis
  • 272
  • 9
  • 24

1 Answers1

1

This is SwiftUI limitation: you can't have more than 10 views on the same level inside any container.

This is because of how SwftUI is built. Imagine each @ViewBuilder function has implementations like this:

func viewBuilder(_ argument1: some View)
func viewBuilder(_ argument1: some View, _ argument2: some View)
...
func viewBuilder(_ argument1: some View, _ argument2: some View, ..., _ argument10: some View)

They had to stop at some point, and it's 10.

You can place your views inside one more Group: this is one of the cases it was made for. Also you can move them into a @ViewBuilder func subgroup() -> some View {}

struct GoalTipsView: View {

    var body: some View {

        NavigationView {

            ScrollView {

                VStack(alignment: .leading) {

                    Group {
                        Group {
                            HStack(spacing: 5) {
                                Text("Using the")
                                Text("Smart").bold()
                                Text("format is important for")
                                Spacer()
                            }.padding(.leading, 7)

                            HStack(spacing: 5) {
                                Text("structuring goals correctly and increases the")
                            }.padding(.leading, 7)

                            HStack(spacing: 5) {
                                Text("chance of success").bold()
                            }.padding(.leading, 7)
                                .padding(.bottom, 35)

                            HStack(spacing: 5) {
                                Text("SPECIFIC").bold().font(.system(size: 23))
                            }.padding(.leading, 10)

                            HStack(spacing: 5) {
                                Text("(Goals that are simple, sensible, significant.) \n A specific goal allows you to focus on a clear and specific target. It can help you visualise the desired outcome and makes it easier to track your progress. Focusing the mind on the desired goals is important for success. Every word needs to be useful and necessary in the goal sentence.")
                                    .padding(5)
                            }.padding(.leading, 7)

                            HStack(spacing: 5) {
                                Text("MEASURABLE").bold().font(.system(size: 23))
                            }.padding(.leading, 10)
                                .padding(.top, 23)

                            HStack(spacing: 5) {
                                Text("(goals that are meaningful, motivating.) \n If your goal isn't measurable, there will be no way to determine if it\'s achieved. Work out the criteria for measuring progress towards the achievement of the goal. \n When the goal is measured you, are much more likely to keep on track, reach milestones, and experience the achievement that is needed for continued effort required to reach the goal.")
                                    .padding(5)
                            }.padding(.leading, 10)

                            HStack(spacing: 5) {
                                Text("To assist with making the goal measurable:").bold().font(.system(size: 18))
                            }.padding(.leading, 10)
                                .padding(.top, 20)

                            HStack(spacing: 5) {
                                Text("How will i know when it is accomplished? \n What exactly needs to happened to consider this goal achieved?")
                                    .padding(5)
                                Spacer()
                            }

                            HStack(spacing: 5) {
                                Text("ASSIGNABLE/ACTION-ORIENTED").bold().font(.system(size: 23))
                            }.padding(.leading, 10)
                                .padding(.top, 23)
                        }


                        HStack(spacing: 5) {} // Extra argument in call


                    }

                }.padding(.top, 10)

            }.navigationBarHidden(true)

        }

    }
}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220