Argument passed to call that takes no arguments
Argument passed to call that takes no arguments
DodaTech
2 min read
The “Argument passed to call that takes no arguments” error means you are supplying parameters to a function or initializer that does not accept any. This is a compile-time error that stops your build.
What It Means
Every function and initializer in Swift has a defined signature listing its parameters. When you provide arguments to a function that expects zero parameters, the compiler flags the mismatch. This often happens due to subtle syntax issues: extra parentheses, calling a computed property as a method, or confusing type construction with a function call.
Why It Happens
- Extra parentheses on a computed property —
view.backgroundColor()instead ofview.backgroundColor. - Calling an initializer with no parameters incorrectly —
MyClass()works butMyClass(param: value)fails if no init takes parameters. - Wrong function name — you intended to call
configure(with: value)but typedconfigure()or vice versa. - Trailing closure syntax confusion — adding a closure argument to a function that does not accept one.
- Calling a method that takes no arguments with empty parentheses incorrectly — writing
someFunc()when the function is defined asfunc someFunc()(this actually works — the error usually means the argument labels do not match or you are passing an argument to a parameter-less function).
How to Fix It
1. Remove the parentheses for computed properties
// ❌ backgroundColor is a property, not a method
let bg = view.backgroundColor()
// ✅ Access as a property
let bg = view.backgroundColor2. Check the function signature
// Given: func reset()
// ❌
reset(animated: true)
// ✅
reset()3. Use the correct initializer
// Given: struct Point { init(x: Int, y: Int) }
// ❌
let p = Point()
// ✅
let p = Point(x: 10, y: 20)4. Remove arguments from parameter-less functions
class ViewController {
func setupUI() {
// ...
}
func viewDidLoad() {
// ❌
setupUI(with: backgroundColor)
// ✅
setupUI()
}
}5. Verify trailing closure usage
// Given: func perform()
// ❌ Trailing closure when function takes no closure
perform() {
print("done")
}
// ✅ Just call the function
perform()Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro