this line usableHeight = NSMenu.menuBarVisible() ? totalHeight - 23 : totalHeight uses ternary operator ; is a condensed form of it then else. It is equivalent to: if NSMenu.menuBarVisible() { usableHeight = totalHeight - 23 } else { usableHeight = totalHeight }. Swift programming language explains « The ternary conditional operator is a special operator with three parts, which takes the form question ? answer1 : answer2. It is a shortcut for evaluating one of two expressions based on whether question is true or false. If question is true, it evaluates answer1 and returns its value; otherwise, it evaluates answer2 and returns its value. ». It is very convenient when you have to set a value depending on condition. For instance let color = (score < 10) ? UIColor.red : UIColor.green
Topic:
Programming Languages
SubTopic:
Swift
Tags: