Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2016 15:51
What would you like to do?
A sample on using flatMap for filtering out nils from an array of String optionals.
let sailorNames: [String?] = [
"Daffy Duck",
"Donald Duck",
"Darkwing Duck",
"Howard The Duck",
let unwrappedSailorNames = sailorNames.flatMap({ $0 })
for sailorName in unwrappedSailorNames {
print(createGreetings(sailorName: sailorName))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment