Sling Academy
Home/Swift/Collection data types in Swift

Collection data types in Swift

Collection data types are types that can store multiple values of the same or different types in an organized way. Swift provides three primary collection types: arrays, sets, and dictionaries.

  • Arrays are ordered collections of values that can be accessed by an integer index. Arrays can store duplicate values and can be modified after creation.
  • Sets are unordered collections of unique values that can be tested for membership and combined using set operations. Sets cannot store duplicate values and can be modified after creation.
  • Dictionaries are unordered collections of key-value pairs that can be accessed by a unique key. Dictionaries can store different types of values for different keys and can be modified after creation.

You can also create your own custom collection types by conforming to the Collection protocol.

This series of tutorials will tell you everything you need to know to confidently deal with Swift collections in real life. Let’s roll up your sleeves and get started!

1 Different Ways to Create an Array in Swift

2 How to Compare 2 Arrays in Swift (Basic & Advanced)

3 Swift: How to find the length of a given array

4 Swift: How to append elements to an array

5 Working with the insert() method in Swift

6 3 Ways to Concatenate Arrays in Swift

7 Swift: Find the index of a specific element in an array

8 Swift: 3 ways to reverse an array

9 Sorting Arrays in Swift: Tutorial & Examples

10 Swift: 5 Ways to Iterate over an Array

11 5 Ways to Remove Elements from an Array in Swift

12 Swift array map() method: Tutorial & examples

13 Swift Array contains() method

14 Swift reduce() method

15 Slicing Arrays in Swift: From Basic to Advanced (with Examples)

16 Swift array filter(): Tutorial & examples

17 Swift difference(from:) method (with examples)

18 Swift: 4 Ways to Shuffle an Array

19 Swift Array.allSatisfy() Method: Tutorial & Examples

20 Swift: Different ways to find the Min/Max of an array

21 Swift: 3 Ways to Swap 2 Elements in an Array

22 Working with Multidimensional Arrays in Swift

23 Swift: 3 Ways to Get a Random Element from an Array

24 Swift: 3 Ways to Remove Duplicates from an Array

25 Swift: Ways to Calculate the Product of an Array

26 Swift: 5 ways to find the sum of a numeric array

27 Swift: 3 ways to calculate the average of a numeric array

28 Swift: 4 Ways to Count the Frequency of Array Elements

29 Swift: How to Convert an Array to JSON

30 Using the zip() function in Swift

31 Creating Dictionaries in Swift (with Examples)

32 Swift: Counting Elements in a Dictionary

33 Swift: Access and Update Values in a Dictionary

34 Swift: Adding new key-value pairs to a dictionary

35 Swift: Removing a key-value pair from a dictionary

36 Swift: Check if a key exists in a dictionary

37 Swift: 5 ways to iterate over a dictionary

38 Merging 2 Dictionaries in Swift

39 Swift: How to Convert a Dictionary to JSON

40 Swift: Converting a Dictionary into an Array

41 How to Create a Set in Swift

42 Adding new Elements to a Set in Swift

43 Swift: Counting the Number of Elements in a Set

44 Swift: Checking if a Set Contains a Specific Element

45 Iterating over a Set in Swift

46 Swift: Removing Elements from a Set (4 Examples)

47 Subtracting 2 Sets in Swift (with Examples)

48 How to Find the Intersection of 2 Sets in Swift

49 How to Find the Union of 2 Sets in Swift

50 Swift: symmetricDifference() and fromSymmetricDifference() methods

51 Swift: How to Convert a Set to an Array and Vice Versa