如何将数据字典转换为Swift数组? [英] How do I convert data dictionary into an array Swift?
本文介绍了如何将数据字典转换为Swift数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Firebase数据作为字典的字典取回:
I'm retrieving firebase data back as a dictionary of dictionary:
guard let data = snapshot.value as? [String: [String:Int]] else {
我正在尝试检索第一个键(?),就像它像这样的结果返回一样:
And I'm trying to retrieve the first key(?) as in if it comes back as a result like this:
"café-veritas": ["AmpleSeating": 1, "Organic": 1, "Quiet": 1, "AmpleOutletAccess": 1, "Couch": 1, "Loud": 1, "GlutenFree": 1, "FreeWifi": 1],
"cafe-myriade": ["Terasse": 1, "LaptopFriendly": 1, "Quiet": 1, "FreeWifi": 1, "FastWifi ": 1, "GlutenFree": 1],
我正在尝试将咖啡馆的名称café-veritas"和"cafe-myriade"放入一个数组中.我被告知要使用地图功能,但不确定如何使用.会是这样吗?
I'm trying to put the name of the cafes, "café-veritas" and "cafe-myriade" into an array. I'm told to use the map function but I'm not sure how. Would it be like this?
let array = data.map { yelp IDs in yelpIDs}
我基本上是想找回钥匙,以便仅是咖啡馆名称.谢谢!
I'm basically trying to get the key back so that all it is is just the cafe name. Thanks!
推荐答案
About using map, I guess this page is helpful and visual.
let names = data.map { return $0.key }
print(names) // prints ["café-veritas", "cafe-myriade"]
这篇关于如何将数据字典转换为Swift数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文