Swift good coding practice: If statement with optional type Bool

前端 未结 3 1174
独厮守ぢ
独厮守ぢ 2021-01-04 11:48

So I\'ve been developing an app in Swift, and today I spent nearly an hour debugging a problem that turned out to be completely unexpected. It all resulted from the code bel

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 12:03

    my advice is to use this nice coalescing ??

    if textfieldDate.text?.isEmpty ?? true {
        // the text is either nil or empty but its all we want to know
    }
    

提交回复
热议问题