Followers

Friday, 11 July 2014

Working with Dictionaries

What is a dictionary ?

It's a container that stores multiple values of same type. In a dictionary each 'values' is associated with a 'Key'. A 'key' in a dictionary will act as an unique identifier.

When to use dictionaries ?

Dictionaries are used when you want to lookup 'values' based on an identifier(key)


In swift the nature of the values and keys are predefined. In other words, the type of keys and values that a particular dictionary can store is always made clear, either through an explicit type annotation or through type inference.

Explicit type annotation:

In the above example we have declared a dictionary called 'dict', contains string type keys and values.

Type inference:



Lets, start working on some examples,
Eg.1

Eg.2

No comments:

Post a Comment