我正在尝试将字典中的值打印成随机顺序,作为我正在制作的游戏的一部分。 问题是,由于某种原因,我无法打印密钥
中的值var die:UInt32 = 0
let windCard = [1:"1 Left", 2:"2 Left", 3:"1 Down Left", 4:"2 Down Left", 5:"1 Down", 6:"2 Down", 7:"1 Right Down", 8:"2 Right Down", 9:"1 Right", 10:"2 Right" ]
die = arc4random()%10+1
print("The wind blow the mosquitoes \(windCard[die:Int])")
答案 0 :(得分:2)
更改
print("The wind blow the mosquitoes \(windCard[die:Int])")
到
print("The wind blow the mosquitoes \(windCard[Int(die)]!)")