Skip to content

Instantly share code, notes, and snippets.

@jrturton
Created December 23, 2014 20:41
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 jrturton/decdce06e81b48441c4f to your computer and use it in GitHub Desktop.
Save jrturton/decdce06e81b48441c4f to your computer and use it in GitHub Desktop.
import Foundation
func coalesce<T>(args: T?...) -> T? {
for possible in args {
if let actual = possible {
return actual
}
}
return nil
}
var optional1 : Int?
var optional2 : Int?
var optional3 : Int?
optional2 = 1
if let valid = coalesce(optional1,optional2,optional3) {
println(valid)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment