Button Argument Passed to call that takes no arguments

Hello Everyone,
I’m doing the foundations course and starting my first app, but I’m going through it the second time around and anytime I try a basic button I get an, “Argument passed to call that takes no arguments”
I feel like I’m coping Chris’s code Exactly. Any insight would be greatly appreciated.

//
//  Button.swift
//  ZKO App
//
//  Created by Daniel Soto on 8/26/24.
//

import SwiftUI

struct Button: View {
    var body: some View {
        Button {
            
        } label: {
            Text("My Custom Button")
                .padding()
                .border(.blue)
        }
        
    }
}

#Preview {
    Button()
}```

There is nothing wrong with the code you have as far as I can tell. What version of Xcode are you using?

Just try cleaning the build folder for that project. There is a couple of ways to do that.

  • press Shift + Command + K simultaneously and respond to the dialogue by selecting Clean.
  • or use the Xcode menu and select Product > Clean Build Folder and respond to the dialogue by selecting Clean.

This should (fingers crossed) cause the code to recompile and the error should disappear.

1 Like

You should rename your view, it’s conflicting because you called your struct Button which is the name of a struct already in SwiftUI

Call yours CustomButton

Argument passed to call that takes no arguments

Means you passed arguments when there are none. Because your struct Button does not have arguments that’s why there’s an error. Xcode thinks you’re using your own Button, when you’re trying to use SwiftUI’s

To technically make this compile you could use SwiftUI.Button in the body, but really the correct way is to rename yours

2 Likes

That was the winner. Thank you.

1 Like