The solution filtershown in the other answers is neat and suitable for this purpose. I will include some more alternatives.
As another alternative, use a simple for ... inconditional loop wherecontaining a condition to increment a counter:
let myArray = ["a", "b", "c", "a", "b", "a", "b", "c", "a", "b"]
var count = 0
for element in myArray where element == "a" { count += 1 }
print(count)
, , reduce:
let myArray = ["a", "b", "c", "a", "b", "a", "b", "c", "a", "b"]
let count = myArray.reduce(0) { $0 + ($1 == "a" ? 1 : 0) }
print(count) //4
NSCounted, @user28434 answer
import Foundation
let myArray = ["a", "b", "c", "a", "b", "a", "b", "c", "a", "b"]
let countedSet = NSCountedSet(array: myArray)
let count = countedSet.count(for: "a")
print(count)
let count = NSCountedSet(array: myArray).count(for: "a")