I would like to check whether a String contains any of the characters 'a', 'e', 'i', 'o' or 'u'.
I understand that the code to write it is:
let target : String = "monocle"
let ok : Bool = target.contains {"aeiou".contains($0)}
// more codes to use the Boolean value of variable 'ok'
Can anyone explain what actually goes on in the second line of the code, i.e. the initialization of the variable ok
?
Edit: To be more specific, I was hoping to find out what actually goes on inside the closure. Thanks to the answer from Sweeper, I now understand that it means checking the String target
, character by character (using shorthand argument name $0
), for any of the characters 'a', 'e', 'i', 'o' or 'u'.