Cannot convert value of type 'Int' to expected argument type 'UInt32'

Declare amountOfQuestions as a UInt32:

var amountOfQuestions: UInt32 = 2

PS: If you want to be grammatically correct it's number of questions.


Make your amountOfQuestions variable an UInt32 rather than an Int inferred by the compiler.

var amountOfQuestions: UInt32 = 2

// ...

var randomNumber = Int(arc4random_uniform(amountOfQuestions - 1)) + 1

arc4random_uniform requires a UInt32.

From the Darwin docs:

arc4random_uniform(u_int32_t upper_bound);

First thing: The method "arc4random_uniform" expects an argument of type UInt32, so when you put that subtraction there, it converted the '1' you wrote to UInt32.

Second thing: In swift you can't subtract a UInt32 (the '1' in your formula) from an Int (in this case 'amountOfQuestions').

To solve it all, you'll have to consider changing the declaration of 'amountOfQuestions' to:

var amountOfQuestions = UInt32(2)

That should do the trick :)