1

I'm having trouble having multiple buttons inside a singular VStack. I get the error: Extra Arguments at positions ... Below is my code. This code is within the View Folders and I am using Xcode12 with SwiftUI

Exact error message: Extra arguments at positions #11, #12, #13 in call

import SwiftUI struct HomeView: View { @Binding var page: Pages var drink = Drink.AllDrinks var body: some View { VStack { drink[0].image .resizable() .frame(width:80, height: 80) Text(drink[0].name) Button(action: {page = Pages.Home}) { OrderButtonContent() } Spacer() .frame(height: 35) drink[1].image .resizable() .frame(width: 80, height: 80) Text(drink[1].name) Button(action: {page = Pages.Home}) { OrderButtonContent } drink[2].image .resizable() .frame(width: 80, height: 80) Text(drink[2].name) Button(action: {page = Pages.Home}) { OrderButtonContent } drink[7].image .resizable() .frame(width: 80, height: 80) Text(drink[7].name) Button(action: {page = Pages.Home}) { OrderButtonContent } } } } struct HomeView_Previews: PreviewProvider { static var previews: some View { HomeView(page: .constant(Pages.Home)) } } struct OrderButtonContent: View { var body: some View { Text("Order") .font(.headline) .foregroundColor(.white) .padding() .frame(width: 80, height: 30) .background(Color.blue) .cornerRadius(15.0) } } 
1

1 Answer 1

1

It is so easy, let see what error say: Exact error message: Extra arguments at positions #11, #12, #13 in call

It says extra arguments! maximum number of arguments are 10 in SwiftUI, we should use Group for this, like this:

struct HomeView: View { @Binding var page: Pages var drink = Drink.AllDrinks var body: some View { VStack { Group { // <<: Here! drink[0].image .resizable() .frame(width:80, height: 80) Text(drink[0].name) Button(action: {page = Pages.Home}) { OrderButtonContent() } Spacer() .frame(height: 35) drink[1].image .resizable() .frame(width: 80, height: 80) Text(drink[1].name) Button(action: {page = Pages.Home}) { OrderButtonContent() } } Group { // <<: Here! drink[2].image .resizable() .frame(width: 80, height: 80) Text(drink[2].name) Button(action: {page = Pages.Home}) { OrderButtonContent() } drink[7].image .resizable() .frame(width: 80, height: 80) Text(drink[7].name) Button(action: {page = Pages.Home}) { OrderButtonContent() } } } } } 
Sign up to request clarification or add additional context in comments.

4 Comments

Ok thank you that works but now I'm getting the error that the argument in my second button in each group is unnamed: Unnamed argument #2 must precede argument 'action' My code is exactly as you showed above with two groups.
You're missing () after most of your OrderButtonContents
use OrderButtonContent() instead of OrderButtonContent
@AryanChordia: I edited the code for you, you forgot () for OrderButtonContent it should be all like: OrderButtonContent()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.