Post

Replies

Boosts

Views

Activity

Comment on Usable screen space in a Mac
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:
Aug ’21
Comment on dfg
Is it a test ? A joke ? A mistake ? A bet ? In any case, not very appropriate for the forum unless you explain your purpose. Have a good day.
Sep ’21
Comment on How to make a button that will print words when i press it.
For more fun, change as:     let citiesEU = ["Paris", "Toulouse", "London", "Milan", "Berlin", "Rome", "Madrid", "Lisbon", "Athens", "Brussels"]            let citiesUS = ["New York", "San Francisco", "Washington", "Dallas", "Cupertino", "Seattle", "Miami", "Chicago", "Detroit", "Phoenix"]                      class Responser: NSObject {     //Method to be called     var tag: Int = 0     @objc func printname() {         var value = "" // 0         switch tag {         case 1: value = citiesEU.randomElement() ?? "No EU city" //  (1...10).randomElement() ?? 1         case 2: value = citiesUS.randomElement() ?? "No US city" //  (11...20).randomElement() ?? 2         default: value = "No city" // 0         }         lbl.text = value // "(value)"     } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Comment on How to tap a row in a UIPickerView
TapGesture will activate when you tap anywhere in the picker, on a row which may be different from selection, isn't it ? And tapping will not change the selection. That could be misleading. Or pickerTapped must first identify which row was tapped, which is not so easy. Or limit the tap to the center of the picker which is where the selection is.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21