Skip to content

Instantly share code, notes, and snippets.

@edopelawi
Created September 13, 2016 15:12
Show Gist options
  • Save edopelawi/1e780ffac24bc85b1173c2e5ba1ae65f to your computer and use it in GitHub Desktop.
Save edopelawi/1e780ffac24bc85b1173c2e5ba1ae65f to your computer and use it in GitHub Desktop.
A sample on unwrapping String optional using guard let and return early strategy.
func guardLetEarlyReturnFunction(sampleName: String?) {
guard let validName = sampleName else {
print("👺 \(#function): Invalid name provided!")
return
}
print(createGreetings(sailorName: validName))
// Add whole other code here :)
}
guardLetEarlyReturnFunction(nil)
guardLetEarlyReturnFunction(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment