我有代码
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
答案 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)%"
}
}