Skip to content

Instantly share code, notes, and snippets.

@michaelnisi
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelnisi/8a587c121f1ce341d423 to your computer and use it in GitHub Desktop.
Save michaelnisi/8a587c121f1ce341d423 to your computer and use it in GitHub Desktop.
Unpack array of any optionals
import Foundation
let items: [Any?] = [0, [], "a", nil, "b", nil, "c"]
let strings = reduce(items, [String]()) {
if let string = $1 as? String {
return $0 + [string]
} else {
return $0
}
}
println(strings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment