我是迅速的早鸟。我有一个字典。我想得到我的键的value.Object的键方法不是为我工作。任何人都可以帮助我吗?
这是我的字典;
var companies = ["AAPL" : "Apple Inc","GOOG" : "Google Inc","AMZN" : "Amazon.com,Inc","FB" : "Facebook Inc"] for (name) in companies.key { println(companies.objectForKey("AAPL")) }
使用此方法,您将看到键和值。
var companies = ["AAPL" : "Apple Inc","FB" : "Facebook Inc"] for (key,value) in companies { println("\(key) -> \(value)") }
或者如果你只想要的值:
for value in companies.values.array { println("\(value)") }
直接访问字典的一个值:
println(companies["AAPL"])