Skip to content

Instantly share code, notes, and snippets.

@deathlezz
Created October 16, 2021 09:26
Show Gist options
  • Save deathlezz/4f20d4491450f280a73fef4207b0786a to your computer and use it in GitHub Desktop.
Save deathlezz/4f20d4491450f280a73fef4207b0786a to your computer and use it in GitHub Desktop.
Ternary operator in Swift 5.
//
// 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