I want to use an Optional variable with the ternary conditional operator but it is throwing error this error: optional cannot be used as boolean. What am I doing wrong?
Ternary operators operate on three targets. Like C, Swift has only one ternary operator, the ternary conditional operator (a ? b : c).
Example usage on tableView
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return section == 2 ? 4 : 1
}
indicates if section equal to 2 then it return 4 otherwise 1 on false.