Crashalot
Crashalot

Reputation: 34503

Swift 2.0: `print` function generates "Argument passed to call that takes no arguments" error

The print function in a class is mysteriously generating the following error: Argument passed to call that takes no arguments.

However, the error goes away if we use Swift.print instead of just print to invoke the function.

We are using Swift 2 and Xcode 7.

Why does this happen?

Test function below where the error gets generated:

func test() {
    print("why does this fail")
}

Upvotes: 2

Views: 3353

Answers (1)

Martin R
Martin R

Reputation: 539705

However, the error goes away if we use Swift.print instead of just print to invoke the function.

That means that there is a print() method defined in your class or in one of its superclasses, so that print() is resolved as the method call self.print().

By prefixing the module name "Swift" you refer to the global print() function instead.

Upvotes: 10

Related Questions