How to create an empty array in Swift?

前端 未结 13 952
耶瑟儿~
耶瑟儿~ 2020-11-30 17:25

I\'m really confused with the ways we create an array in Swift. Could you please tell me how many ways to create an empty array with some detail?

13条回答
  •  没有蜡笔的小新
    2020-11-30 18:07

    There are 2 major ways to create/intialize an array in swift.

    var myArray = [Double]()
    

    This would create an array of Doubles.

    var myDoubles = [Double](count: 5, repeatedValue: 2.0)
    

    This would create an array of 5 doubles, all initialized with the value of 2.0.

提交回复
热议问题