我有这种类型的词典:
var emojiChoices = [0 : ["","","","","","","",""], 1 : ["⚽️","","","","","♀️","",""]]
我想要一个其他元素来显示“0”键中包含的字符串。
感谢您的帮助。
答案 0 :(得分:1)
您可以通过键访问字典中的项目:emojiChoices [key]。例如:
var emojiChoices = [0 : ["","","","","","","",""], 1 : ["⚽️","","","","","♀️","",""]]
let result = emojiChoices[0]
对于随机密钥:
var emojiChoices = [0 : ["","","","","","","",""],
1 : ["⚽️","","","","","♀️","",""]]
if let array = emojiChoices[0] {
let randomIndex = Int(arc4random_uniform(UInt32(array.count)))
let randomEmoji = array[randomIndex]
print(randomEmoji)
}