Mention what are the collection types available in Swift?



Mention what are the collection types available in Swift?..

Answer / 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

More Apple iOS Swift Interview Questions

Is multiple inheritance possible in swift?

0 Answers  


Is swift a functional language?

0 Answers  


Can any be nil swift?

0 Answers  


Why do we use swift? Mention some advantages of swift?

0 Answers  


Can enum be extended in swift?

0 Answers  






What are generics? How to make a method or variable generics in swift?

0 Answers  


What type of objects are basic data types in swift?

0 Answers  


What is swift programming language?

0 Answers  


Is equal to string swift?

0 Answers  


What is extension in swift?

0 Answers  


What is data structure in swift?

0 Answers  


Which banks use swift?

0 Answers  


Categories