Swift: How To Count Occurrences of a Character in a Swift String

To count occurrences of a character in a Swift String, you can use Sequence.filter and then Array.count:

"dA Snippets".filter({ $0 == "p"}).count

Output:

2