Skip to content

Instantly share code, notes, and snippets.

@mildocjr
Created August 11, 2018 01:54
Show Gist options
  • Save mildocjr/0c3c97c4ca60b96e3a7e9fa98b733ea5 to your computer and use it in GitHub Desktop.
Save mildocjr/0c3c97c4ca60b96e3a7e9fa98b733ea5 to your computer and use it in GitHub Desktop.
if-let-3
func add(firstPossibleInteger: Int?, secondPossibleInteger: Int?) -> Int? {
guard let firstNumber = firstPossibleInteger,
let secondNumber = secondPossibleNumber
else { return nil } // or 0 if you want to return a
// non-optional value
return (firstNumber + secondNumber)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment