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)
    }
}

  • 3
    Does this answer your question? [SwiftUI: Random "Extra argument in call" error](https://stackoverflow.com/questions/61178868/swiftui-random-extra-argument-in-call-error) – jnpdx Apr 09 '21 at 22:43

1 Answers1

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()
                }
                
            }
            

            
            
        }
    }
}
ios coder
  • 1
  • 4
  • 31
  • 91
  • 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. – Aryan Chordia Apr 09 '21 at 22:50
  • 1
    You're missing `()` after most of your `OrderButtonContent`s – jnpdx Apr 09 '21 at 22:57
  • 1
    use `OrderButtonContent()` instead of `OrderButtonContent` – ios coder Apr 09 '21 at 22:58
  • 1
    @AryanChordia: I edited the code for you, you forgot `()` for `OrderButtonContent` it should be all like: `OrderButtonContent()` – ios coder Apr 09 '21 at 23:00