Dictionaries in Swift

You may know that in Swift arrays to read out a value, you can call it’s index value similar to:

var someArray = ["Farhan", "Syed", "March", "19", "1996"]

someArray[0]

Instead of remembering the index value that is assigned to each value we can re-write this with a dictionary.

By dictionaries, instead of arbitrary numbers you have read and write values using a key you identify.

Let’s build a simple organized dictionary:

var someDictionary = [

"firstName":"Farhan",
 "lastName":"Syed",
 "month":"March",
 "day":"19",
 "year":"1996"
 
]

You can read into a dictionary like so:

someDictionary["firstName"]

You can observe with dictionaries, you build it by writing it’s key, then a colon, then it’s value.

You can read any value from the dictionary you build by knowing the key.

Last Update: October 10, 2018  

October 10, 2018   89   Nandini R    Swift Significance    
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
INSTAGRAM
LinkedIn