What's the difference between [Int] & Array?

后端 未结 1 1091
执笔经年
执笔经年 2021-01-14 14:45
let numberList = Array(1...10) // type == Array
let numberList2 = [1,2,3,4,5,6,7,8,9,10] // type == [Int]

The code above assigns the com

相关标签:
1条回答
  • 2021-01-14 15:09

    From The Swift Programming Language: Collection Types

    Array Type Shorthand Syntax

    The type of a Swift array is written in full as Array<SomeType>, where SomeType is the type of values the array is allowed to store. You can also write the type of an array in shorthand form as [SomeType]. Although the two forms are functionally identical, - the shorthand form is preferred and is used throughout this guide when referring to the type of an array.

    That is, both comments are correct - and both represent the same type.

    0 讨论(0)
提交回复
热议问题