Skip to content

Instantly share code, notes, and snippets.

@edopelawi
Last active October 12, 2016 14:07
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 edopelawi/0a199ded65b76108233cf7a43a95cc00 to your computer and use it in GitHub Desktop.
Save edopelawi/0a199ded65b76108233cf7a43a95cc00 to your computer and use it in GitHub Desktop.
A sample on unwrapping String optional using switch's pattern matching.
func printSailorName(sailorName sailorName: String?) {
switch sailorName {
case .some(let validName):
print(createGreetings(sailorName: validName))
case .none:
print("👺 The sailor name input is invalid!")
}
}
printSailorName(sailorName: nil)
printSailorName(sailorName: name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment