Swift Collection Types (Arrays, Sets, Dictionaries)

In swift, collections are used to store or hold a collection of multiple values in one place. We have multiple types of collections available in swift programming language those are

 

  • Arrays
  • Sets
  • Dictionaries

Swift Array Collection Types

In swift arrays are used to store same type of multiple values in an ordered manner. In an array we can store same value in multiple times at different positions based on our requirements.

 

Following is the simple pictorial representation of arrays in the swift programming language.

 

Swift Array Collection Types with Examples

 

If you want to learn more about arrays in a swift programming language, check the Swift Arrays article.

Swift Set Collection Types

In swift sets are useful to store same type of distinct values in an unordered manner. We can use sets instead of arrays in case if we want to store only distinct values and we are not concerned about the order of items. 

 

Following is the simple pictorial representation of sets in swift programming language.

 

Swift Set Collection Types with Examples

 

If you want to learn more about sets in a swift programming language, check the Swift Sets article.

Swift Dictionary Collection Types

In swift dictionaries are used to store values with key-value pair association in an unordered manner. In dictionaries, we can store the same type of keys and the same type of values with no defined order. The keys in dictionaries must be unique and those will act as identifiers for the values in dictionaries.

 

We can use dictionaries in swift programming language whenever we want to get values based on the key values.

 

Following is the simple pictorial representation of dictionaries in the swift programming language.

 

Swift Dictionary Collection Types with Examples

 

If you want to learn more about dictionaries in swift programming language, check Swift Dictionaries article.