Initialising empty arrays of dictionaries in Swift

后端 未结 6 1248
北恋
北恋 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:30

    You can no longer use element concatenation.

    class Image {}
    Image i1
    Image i2
    
    var x = [Image]()
    
    x += i1 // will not work (adding an element is ambiguous)
    x += [i1] // this will work (concatenate an array to an array with the same elements)
    
    x += [i1, i2] // also good
    

提交回复
热议问题