Last active
May 30, 2018 12:06
-
-
Save dineshba/9ceb91ccdd482912d680452f5add82ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var optionalValue: Int? | |
if let value = optionalValue { // unwraps optionalValue and assigns | |
// it to variable named value | |
print(value) // type of value = Int | |
else { | |
print("not able to unwrap optionalValue as it is nil") | |
} | |
//Let's rewrite the sum function using if-let | |
func sum(_ optionalAugend: Int?, _ optionalAddend: Int?) -> Int? { | |
if let augend = optionalAugend, | |
let addend = optionalAddend {// `,` is AND operation. | |
// If both variables are unwrapped, enter into if-case | |
return augend + addend | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment