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

问题描述 投票:-2回答:1

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

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])")
swift dictionary
1个回答
2
投票

更改

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

print("The wind blow the mosquitoes \(windCard[Int(die)]!)")
© www.soinside.com 2019 - 2024. All rights reserved.