Swift good coding practice: If statement with optional type Bool

前端 未结 3 1172
独厮守ぢ
独厮守ぢ 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:14

    If the bool is part if Core Data (aka NSNumber), you should do it like this.

    if (isHero.isAI?.boolValue != nil)
    

    Regards

提交回复
热议问题