Johnd Johnd - 1 year ago 161
Swift Question

arc4random Swift 3 syntax

I made a quiz app in Swift 2 I'm trying to update the syntax from random to arc4random...

if Questions.count > 0 && counter <= 15 {
QNumber = arc4random()% Questions.count
QLabel.text = Questions[QNumber].Question

AnswerNumber = Questions[QNumber].Answer

for i in 0..<Buttons.count{
Buttons[i].setTitle(Questions[QNumber].Answers[i], for: UIControlState())
}
Questions.remove(at: QNumber)
}

Answer Source

It's recommended to use arc4random_uniform instead of simple arc4random.

arc4random_uniform expects an UInt32 parameter so you have to convert the values back and forth

qNumber = Int(arc4random_uniform(UInt32(questions.count)))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download