How to use the conditional ternary operator in Swift

2 Answers

0 votes
import Foundation

let isTrue = true

let result = isTrue ? "Yes" : "No"

print(result) 



/*
run:

Yes

*/

 



answered May 13 by avibootz
0 votes
import Foundation

let age = 18

let canVote = age >= 18 ? "Yes, you can vote." : "No, you cannot vote."

print(canVote) 



/*
run:

Yes, you can vote.

*/

 



answered May 13 by avibootz
...