Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to generate a random number in Swift:

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

but this results in the error:

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

What is the problem? Any ideas on what I can do to fix this error?

like image 996
Tom Fox Avatar asked Feb 22 '16 19:02

Tom Fox


1 Answers

Declare amountOfQuestions as a UInt32:

var amountOfQuestions: UInt32 = 2

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

like image 123
yesthisisjoe Avatar answered Sep 21 '22 09:09

yesthisisjoe