Skip to content

Instantly share code, notes, and snippets.

@edopelawi
Created September 13, 2016 15:08
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/fbc1b68e56651b41be2a33bb404c799f to your computer and use it in GitHub Desktop.
Save edopelawi/fbc1b68e56651b41be2a33bb404c799f to your computer and use it in GitHub Desktop.
A sample on unwrapping String optional using force-unwrap to return early.
func sampleEarlyReturnFunction(sampleName: String?) {
if sampleName == nil {
return
}
let anotherName = sampleName!
print(createGreetings(sailorName: anotherName))
}
// This code will do just fine, even the name has nil value.
sampleEarlyReturnFunction(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment