How to count frequency of elements in an array in Swift

Given an array of elements, sometimes you want to calculate how many times each element will occur in the given array. To do that let's follow the steps:

Step 1: First create an array of string

let arrayOfString = ["Volvo", "BMW", "Ford", "Volvo", "Mazda", "BMW", "Mercedes-Benz", "Ford", "Volvo"]

Step 2: Convert the array into key-value pair using tuples

let tupleArray = arrayOfString.map { ($0, 1) }