我试图将字典中的值打印成随机顺序,作为我正在制作的游戏的一部分。问题是由于某种原因我无法从密钥中打印出值
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])")
更改
print("The wind blow the mosquitoes \(windCard[die:Int])")
至
print("The wind blow the mosquitoes \(windCard[Int(die)]!)")