Last active
August 29, 2015 14:20
-
-
Save michaelnisi/8a587c121f1ce341d423 to your computer and use it in GitHub Desktop.
Unpack array of any optionals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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