Please Help Me Intepret This Code SWIFT

前端 未结 4 577
遥遥无期
遥遥无期 2020-12-07 05:35
display.text = newValue != nil ? \"\\(newValue!)\" : \" \" 

Does the syntax of the code mean, let display.text = newValue, if it does not equal nil

4条回答
  •  悲&欢浪女
    2020-12-07 06:37

    it means that

    if newValue == nil {
        display.text = " "
    } else {
        display.text = "(newValue!)"
    }
    

    if newValue is not nil, display.text will be (newValue!).

    if you want to show newValue's value,

    you should write that

    if newValue == nil {
        display.text = " "
    } else {
        display.text = "\(newValue!)"
    }
    

提交回复
热议问题