Skip to content

Instantly share code, notes, and snippets.

@mahmudahsan
Created August 22, 2017 06:50
Show Gist options
  • Save mahmudahsan/eecbf750df44ce656dfb1773e1c27f62 to your computer and use it in GitHub Desktop.
Save mahmudahsan/eecbf750df44ce656dfb1773e1c27f62 to your computer and use it in GitHub Desktop.
var score:Int?
score = 100
//if score is nil the if block will not work
/*if score has value, the if block create a new constant score and assign the score value to the new constant score which is unwrapped and available within the if block
*/
if let score = score{
score
}
score ?? 0 //provide a default value when there is nil
score! //when u sure the optional must have a value other than nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment