Search code examples
swift3iboutletarc4random

IBOutlet with arc4random in swift3.0


i have code

class ViewController: UIViewController {

var detailText: String = "Chance of win is 50%"

@IBOutlet weak var winChance: UILabel!

func someMethod () -> Void {
    print("Method called!")
}

override func viewDidLoad() {
    super.viewDidLoad()
self.winChance.text = self.detailText
}    }

how can i make arc4random for this 50%?? if i used something with "(var)" it is not help me Thnx


Solution

  • Try this

    class ViewController: UIViewController {
    
        @IBOutlet weak var winChance: UILabel!
    
        func someMethod () -> Void {
            print("Method called!")
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
            let randomNumber = Int(arc4random_uniform(100))
            self.winChance.text = "Chance of win is \(randomNumber)%"
        }    
    }