Initialising empty arrays of dictionaries in Swift

后端 未结 6 1228
北恋
北恋 2021-01-30 02:18

I\'m trying to wrap my head around initialising empty arrays in Swift.

For an array of strings it\'s pretty straight forward :

var myStringArray: String         


        
6条回答
  •  清酒与你
    2021-01-30 02:38

    The reason this isn't working:

    var myNewDictArray: Dictionary[] = []
    

    is that you need to provide types for the keys and values of a dictionary when you define it. Each of these lines will create you an empty array of dictionaries with string keys and string values:

    var dictArray1: Dictionary[] = Dictionary[]()
    var dictArray2: Dictionary[] = []
    var dictArray3 = Dictionary[]()
    

提交回复
热议问题