Created
September 15, 2022 08:33
-
-
Save AhmedMenaim/ad673ac1c7c8dad1e729b3223e356781 to your computer and use it in GitHub Desktop.
Menaim Academy - Swift Course - Optionals
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
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