How to create an empty array in Swift?

前端 未结 13 933
耶瑟儿~
耶瑟儿~ 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

    Compatible with: Xcode 6.0.1+

    You can create an empty array by specifying the Element type of your array in the declaration.

    For example:

    // Shortened forms are preferred
    var emptyDoubles: [Double] = []
    
    // The full type name is also allowed
    var emptyFloats: Array = Array()
    

    Example from the apple developer page (Array):

    Hope this helps anyone stumbling onto this page.

提交回复
热议问题