Mention what are the collection types available in Swift?
Answer Posted / iosraj
In Swift, collection types come in two varieties Array and Dictionary
Array: You can create an Array of a single type or an array with multiple types. Swift usually prefers the former one
Example for single type array is,
Var cardName : [String] = [ “Robert” , “Lisa” , “Kevin”]
// Swift can infer [String] so we can also write it as:
Var cardNames = [ “Robert”, “Lisa”, “Kevin”] // inferred as [String]
To add an array you need to use the subscript println(CardNames[0])
Dictionary: It is similar to a Hash table as in other programming language. A dictionary enables you to store key-value pairs and access the value by providing the key
var cards = [ “Robert”: 22, “Lisa” : 24, and “Kevin”: 26]
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is swift nsarray?
How to write a multiple line comment in swift?
What is retain in swift?
What are the two main integer types in swift?
What is nil-coalescing operator?
What is the floating point numbers and what are the types of floating number in swift?
What is differences in swift 1.x, 2.x, 3.x, 4.x?
What is core data swift?
Is swift like python?
What is the significance of “?” In swift?
What are the control transfer statements that are used in ios swift?
What is bridging header in swift?
What is protocol in swift?
What is an attribute in swift?
Do try catch swift?