The filter function can be called as a global function over an array or as an instance method (I prefer later ones, since this is more OO).
It takes a closure with one parameter (evaluated element), which returns a boolean value (indicates whether the element meets the required condition).
Since this is a simple closure in a clear situation, an abbreviated form can be used.
I assume that other C cases will be added to your listing, so you can go with something like:
let filteredArray = enums.filter { switch $0 { case let .WithString(value): return value == "C" default: return false } }
This should do the trick in your example.
source share