Swift cannot call '*' with argument list like '(Int, Int)'

So, I was trying to write basic Swift, and I wrote:

func timesByHundred(d: Int) {
    return d * 100
}

      

and the compiler said it "cannot call" * "with an argument list of type (Int, IntegerLiteralConvertible)". So I changed it to:

func timesByHundred(d: Int) {
    let e: Int = 100
    return d * e
}

      

and the compiler said it "can't call" * "with an argument list like" (Int, Int) ". What can I even multiply if not two ints? There are some similar questions in there, but all have people trying to work on different types.

+3


source to share


1 answer


Compiler error is misleading.

The real problem is that you missed the return type declaration of the function, so the compiler reports Void

and it gets confused when you try (and fail) to find a suitable overload for *

that returns Void

.



Change your function to

func timesByHundred(d: Int) -> Int {
    return d * 100
}

      

+9


source







All Articles