Evaluate Bool property of optional object in if statement

后端 未结 3 1744
失恋的感觉
失恋的感觉 2020-12-31 13:11

I am looking for a way to evaluate a Swift Bool concisely in a single if statement, when the Bool is the property of an optional objec

3条回答
  •  清歌不尽
    2020-12-31 13:26

    You could also do :

    if let obj = objectWithBool where obj {
        // objectWithBool != nil && obj == true
    } else {
       // objectWithBool == nil || obj == false
    }
    

提交回复
热议问题