在迅速字典键阵列 [英] Array from dictionary keys in swift

查看:160
本文介绍了在迅速字典键阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图填补从钥匙串数组在迅速的字典。

  VAR componentArray:[字符串]让字典=的NSDictionary(contentsOfFile:NSBundle.mainBundle()pathForResource(组件,ofType:plist中)!)
componentArray = dict.allKeys

这将返回一个错误:AnyObject'不相同字符串

也试过

  componentArray = dict.allKeys为String

但得到的:'串'是无法转换为[字符串]


解决方案

  componentArray =阵列(dict.keys)

Trying to fill an array with strings from the keys in a dictionary in swift.

var componentArray: [String]

let dict = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("Components", ofType: "plist")!)
componentArray = dict.allKeys

This returns an error of: 'AnyObject' not identical to string

Also tried

componentArray = dict.allKeys as String 

but get: 'String' is not convertible to [String]

解决方案

componentArray = Array(dict.keys)

这篇关于在迅速字典键阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆