0

When I use conditional operator in Swift, like this: let foo = array.count < 0? 0 : array.count I got error:

Consecutive statements on a line must be separated by ';'

I know that ? in swift is used to unwrap optional.

Should I use this operator in swift?

If I can, how?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
XM Zhang
  • 123
  • 1
  • 10

1 Answers1

6

spacing should be either

let foo = array.count < 0 ? 0 : array.count

or

let foo = array.count<0 ? 0:array.count
Rukshan
  • 7,902
  • 6
  • 43
  • 61