尝试使用swift中的随机键从字典中打印值时遇到问题

时间:2018-05-30 17:13:02

标签: swift dictionary

我正在尝试将字典中的值打印成随机顺序,作为我正在制作的游戏的一部分。 问题是,由于某种原因,我无法打印密钥

中的值
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])")

1 个答案:

答案 0 :(得分:2)

更改

print("The wind blow the mosquitoes \(windCard[die:Int])")

print("The wind blow the mosquitoes \(windCard[Int(die)]!)")