Skip to content

Instantly share code, notes, and snippets.

@edopelawi
Created September 13, 2016 15:51
Embed
What would you like to do?
A sample on using flatMap for filtering out nils from an array of String optionals.
let sailorNames: [String?] = [
nil,
"Daffy Duck",
"Donald Duck",
nil,
"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