在swift3.0中使用arc4random的IBOutlet

时间:2017-04-16 19:42:43

标签: swift3 iboutlet arc4random

我有代码

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
}    }

如何为这50%制作arc4random? 如果我用"(var)"这对我没有帮助 日Thnx

1 个答案:

答案 0 :(得分:0)

试试这个

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)%"
    }    
}