Which is better way to declare Array and Dictionary, I have used both:
Array<String>
[String]
For me [String]
is very fast in terms of coding but in reality how both are different in terms of compiler and performance and which one we should follow?
The main difference between Array and String is that an Array is a data structure that stores a set of elements of the same data type while a String is a set of characters. Programming languages such as C supports arrays and strings.
In programming, an array is a collection of the homogeneous types of data stored in a consecutive memory location and each data can be accessed using its index. In the Java programming language, we have a String data type. The string is nothing but an object representing a sequence of char values.
The main difference between an array and a string is that an array is a data structure, while a string is an object. Arrays can hold any data types, while strings hold only char data types. Arrays are mutable, while strings are not. Arrays have a fixed length, while strings do not.
From iOS Developer Library on Swift...
The type of a Swift array is written in full as Array< Element >, where Element is the type of values the array is allowed to store. You can also write the type of an array in shorthand form as [Element]. 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.
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html
The two are equivalent.
From Apple
Array Type Shorthand Syntax
The type of a Swift array is written in full as Array, where Element is the type of values the array is allowed to store. You can also write the type of an array in shorthand form as [Element]. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With