开发者社区 问答 正文

快速从字典键数组

尝试使用字典中的键快速填充字符串。

var componentArray: [String]

let dict = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("Components", ofType: "plist")!) componentArray = dict.allKeys 这将返回错误:'AnyObject'与字符串不同

也尝试过

componentArray = dict.allKeys as String 但得到:'String'不能转换为[String]

展开
收起
保持可爱mmm 2020-01-16 15:36:02 347 分享 版权
1 条回答
写回答
取消 提交回答
  • Swift 3和Swift 4

    componentArray = Array(dict.keys) // for Dictionary

    componentArray = dict.allKeys // for NSDictionary

    问题来源于stack overflow

    2020-01-16 15:36:18
    赞同 展开评论
问答地址: