Created
October 16, 2021 09:26
-
-
Save deathlezz/4f20d4491450f280a73fef4207b0786a to your computer and use it in GitHub Desktop.
Ternary operator in Swift 5.
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
// | |
// Ternary operator | |
// | |
// example #1 | |
var first = 4 | |
var second = 5 | |
print(first == second ? "Numbers are equal" : "Numbers are different") // Numbers are different | |
// example #2 | |
let string = "b" | |
let number = Int(string) | |
print(number ?? "Conversion error") // Conversion error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment