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


Please Help Members By Posting Answers For Below Questions

What is a tuple in swift?

391


What is data structure in swift?

447


What is a static variable swift?

464


How is swift different from objective-c?

479


What is floating point number in swift? What are the different floating point numbers in swift?

492






What is base class in swift?

434


Is "swift" a good programming language? Explain

464


Is swift garbage collected?

538


What type of literals does swift language have?

464


What are the characteristics of switch?

480


What is forced unwrapping? Why is it potentially unsafe?

488


What is argument label in swift?

439


What is a swift class?

431


How do I create a swift file in xcode?

465


Which banks use swift?

428