Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AhmedMenaim/ad673ac1c7c8dad1e729b3223e356781 to your computer and use it in GitHub Desktop.
Save AhmedMenaim/ad673ac1c7c8dad1e729b3223e356781 to your computer and use it in GitHub Desktop.
Menaim Academy - Swift Course - Optionals
import Foundation
var stringNumber: String? // We can identify any optional variable using -> ?
var number = 5
//print(Int(stringNumber!)! + number) // Force unwrapping -> ! = Make sure that I have a value here
//var sreing1 = ""
//stringNumber = "5"
print(Int(stringNumber ?? "1")! + number) // if this string has a value use it, if not guve it an empty string -> ""
// ?? -> Provides a default value
// guard, if let
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment