tobygriffin
tobygriffin

Reputation: 5421

Multiplying integers

I am certain I am missing something very, very obvious, but can anyone tell me why I am having trouble multiplying two Integers? The following code:

let twenty: Integer = 20
let ten: Integer = 10
let result: Integer = twenty * ten

presents the error Could not find an overload for '*' that accepts the supplied arguments.

Other questions on SO with the same error are caused by trying to multiply different types together, but surely these are both Integer types?

(PS: The actual code I am trying to run is var value = self.value * 10 but I have expanded it to the sample while debugging to make absolutely sure that the correct types are being used)

Upvotes: 1

Views: 7499

Answers (3)

Kumar KL
Kumar KL

Reputation: 15335

As already stated , Integer is a protocol not a type .

In your situation, you don't need to do explicit the type because it is of implicit casting.

This could be enough

 let twenty = 20
 let ten = 10
 let result = twenty * ten

 NSLog("%d", result)

Upvotes: 1

Rod
Rod

Reputation: 55752

Integer is a protocol not a type. Use Int instead.

Upvotes: 4

shucao
shucao

Reputation: 2242

use Int instead. Integer is a protocol.

Upvotes: 5

Related Questions