本文介绍了斯威夫特:字典里面阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据:
[
{ firstName: "Foo", lastName: "Bar" },
{ firstName: "John", lastName: "Doe" }
]
我怎么能使用SWIFT数组和字典这样的结构?这一数据说明内部数组字典,对不对?因此,我建议:
How can I have this kind of structure using swift array and dictionary? This data shows dictionaries inside an array, right? So I suggest:
var persons:Array = [Dictionary<String, String>()]
但是这给我的错误:
but this gives me the error:
Cannot convert the expressions type () to type Array<T>
任何想法?
推荐答案
正确的方法是:
var persons = [Dictionary<String, String>]()
这相当于:
var persons = [[String : String]]()
你的code做反而是创建一个实例词典&LT填充数组;字符串,字符串&GT;
,而我想要presume字符串,字符串&GT;含元素字典&LT数组的一个空的实例。
键入
What your code does instead is to create an array filled in with an instance of Dictionary<String, String>
, whereas I presume you want an empty instance of the array containing elements of Dictionary<String, String>
type.
这篇关于斯威夫特:字典里面阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!