Skip to content

Instantly share code, notes, and snippets.

@patr1ck
Last active August 25, 2016 20:43
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 patr1ck/c6f425d5f627a516d708 to your computer and use it in GitHub Desktop.
Save patr1ck/c6f425d5f627a516d708 to your computer and use it in GitHub Desktop.
Polymorphic Function Returns in Swift
// In Swift, functions can be defined with identical parameter types, but different return types.
func isHello(string: String) -> Bool {
if string == "Hello" {
return true
} else {
return false
}
}
func isHello(string: String) -> String {
if string == "Hello" {
return "Yep"
} else {
return "Nope"
}
}
let numberResult: Bool = isHello("Hello")
// => true
let stringResult: String = isHello("Hello")
// => "Yep"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment