Extra argument in call when adding a new line of text

Hello!

I wonder what is wrong with my code:

when I add a new line of text after the text "purpose", it says EXTRA ARGUMENT IN CALL.

i can't seem to figure out why.

I also wanted to format the paragraphs as "justified"

this is the snippet of the code: also, I am just starting to learn to code (I've started this just less than a week ago, your input would greatly be appreciated)

Thank you!

struct TableViewCell1Content: View { var body: some View { ScrollView { VStack(alignment: .center, spacing: 20) { Image("natural") .resizable() .cornerRadius(25) .aspectRatio(contentMode: .fit) .frame(maxWidth: 500) .padding(.bottom, 10)

            Text("Natural Slope")
                .font(.largeTitle)
                .underline()
            
            Text("Paragraph 1 over here . . . . . long 300-words at least")
                .font(.body)
                .multilineTextAlignment(.leading)
                .lineSpacing(5)
                .padding(.horizontal, 40)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.bottom, 30)
            
            Image("artificial")
                .resizable()
                .cornerRadius(25)
                .aspectRatio(contentMode: .fit)
                .frame(maxWidth: 500)
                .padding(.bottom, 10)
            
            Text("Artificial Slope")
                .font(.largeTitle)
                .underline()
            
            Text("another paragraph in this area containing 300 words")
                .font(.body)
                .multilineTextAlignment(.leading)
                .lineSpacing(5)
                .padding(.horizontal, 40)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.bottom, 30)
            
            Image("reinforced")
                .resizable()
                .cornerRadius(25)
                .aspectRatio(contentMode: .fit)
                .frame(maxWidth: 500)
                .padding(.bottom, 10)
            
            Text("Reinforced Slope and Gabions")
                .font(.largeTitle)
                .underline()
            
            Text("another paragraph words words words words words")
                .font(.system(size:20))
                .multilineTextAlignment(.leading)
                .lineSpacing(5)
                .padding(.horizontal, 50)
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(.bottom, 50)
            
            //this part should show the purpose and scope
            
            Text("Purpose")
                .font(.largeTitle)
                .underline()
            
            Text("this should be a single paragraph explaining the purpose of this app")
            
            
           
        }
        .frame(maxWidth: .infinity)
        .padding()

        .alignmentGuide(HorizontalAlignment.center) { _ in
                        UIScreen.main.bounds.size.width / 2 / 2 // Align VStack at the center horizontally
        }
    }
    .background(Color.brown.opacity(0.3))
}

}

Answered by szymczyk in 757249022

A SwiftUI view is limited to 10 subviews. If you have more than 10 subviews, you will get an Extra Arguments build error. It looks like you have more than 10 Text and Image views inside your table cell view.

The workaround is to place your Text and Image views in multiple groups.

Group {
  Text("Natural Slope")
  Text("Paragraph 1 over here . . . . . long 300-words at least")
  Image("artificial")
  Text("Artificial Slope")
  Text("another paragraph in this area containing 300 words")
}

Group {
  Image("reinforced")
  Text("Reinforced Slope and Gabions")
  Text("another paragraph words words words words words")
  Text("Purpose")
  Text("this should be a single paragraph explaining the purpose of this app")
}

Notice how each group has fewer than 10 subviews inside them.

I omitted the modifiers for the Text and Image views to keep the code block from getting too long.

Accepted Answer

A SwiftUI view is limited to 10 subviews. If you have more than 10 subviews, you will get an Extra Arguments build error. It looks like you have more than 10 Text and Image views inside your table cell view.

The workaround is to place your Text and Image views in multiple groups.

Group {
  Text("Natural Slope")
  Text("Paragraph 1 over here . . . . . long 300-words at least")
  Image("artificial")
  Text("Artificial Slope")
  Text("another paragraph in this area containing 300 words")
}

Group {
  Image("reinforced")
  Text("Reinforced Slope and Gabions")
  Text("another paragraph words words words words words")
  Text("Purpose")
  Text("this should be a single paragraph explaining the purpose of this app")
}

Notice how each group has fewer than 10 subviews inside them.

I omitted the modifiers for the Text and Image views to keep the code block from getting too long.

Thank You so much!

Extra argument in call when adding a new line of text
 
 
Q