Arrays 如何在swift中获取数组中字典的值

Arrays 如何在swift中获取数组中字典的值,arrays,swift,dictionary,ios8,Arrays,Swift,Dictionary,Ios8,我有这样的字典 var dict : [String : Array<String>] = ["Fruits" : ["Mango", "Apple", "Banana"],"Flowers" : ["Rose", "Lotus","Jasmine"],"Vegetables" : ["Tomato", "Potato","Chilli"]] var dict:[String:Array]=[“水果”:[“芒果”、“苹果”、“香蕉”],“花朵”:[“玫瑰”、“莲花”、“茉莉花”],

我有这样的字典

var dict : [String : Array<String>] = ["Fruits" : ["Mango", "Apple", "Banana"],"Flowers" : ["Rose", "Lotus","Jasmine"],"Vegetables" : ["Tomato", "Potato","Chilli"]]
var dict:[String:Array]=[“水果”:[“芒果”、“苹果”、“香蕉”],“花朵”:[“玫瑰”、“莲花”、“茉莉花”],“蔬菜”:[“番茄”、“土豆”、“辣椒”]]
我想在数组中为每个键获取值如何在swift中获取值?

编辑: 试试这样的

var dict : [String : Array<String>] = [
                                        "Fruits" : ["Mango", "Apple", "Banana"],
                                        "Flowers" : ["Rose", "Lotus","Jasmine"],
                                        "Vegetables" : ["Tomato", "Potato","Chilli"]
                                      ]


var myArray : Array<String> = []
// You can access the dictionary(dict) by the keys(Flowers, Flowers, Vegetables)
// Here I'm appending the array(myArray), by the accessed values.
myArray += dict["Fruits"]!
myArray += dict["Vegetables"]!

print("myArray \(myArray)")
值数组:[“玫瑰”、“莲花”、“茉莉花”、“西红柿”、“土豆”, “辣椒”、“芒果”、“苹果”、“香蕉”]

尝试:

试试这个:

for (key, value) in dict {
    println("key=\(key), value=\(value)")
}

尝试获取如下代码所示的值

let fruits = dict["Fruits"]
let flowers = dict["Flowers"]
let vegetables = dict["Vegetables"]

2年半,没有人提及
map

好的,撇开
字典
有一个(如图所示)可以满足您的要求,您可以:

let values = dict.map { $0.value }
let fruits = dict["Fruits"]
let flowers = dict["Flowers"]
let vegetables = dict["Vegetables"]
for val in dict.values {
    print("Value -> \(val)")
}
let values = dict.map { $0.value }