[Type]
instead of Array<Type>
SW-C1003Using the shorthand syntactic sugar for defining arrays, i.e., []
instead of
Array
, can make the code more concise and readable. Here are some reasons
why:
Readability: Using the shorthand notation can make the code more concise, and it is easier to read and understand. It is a common practice in Swift and most other languages, and most developers expect to see it.
Ease of Use: Using the shorthand notation can make it easier to work with arrays, as it is more natural and requires less typing. It is also easier to remember the syntax, which can save time and reduce the number of errors.
In summary, using the shorthand notation for defining arrays in Swift can improve the readability, and make it easier to use. It is generally recommended to use the shorthand notation whenever possible.
let numbers: Array<Int> = [1, 2, 3]
let x: Optional<Int>
let numbers: [Int] = [1, 2, 3]
let x: Int?