Search code examples
swiftnullconditional-statementslogical-or

Logical OR in mutiple condition with a nil expression


Since 30 minutes I'm looking for a compiling solution for this objective-c condition that I want write in swift

if (session == nil || ![session isValid]) {

}

Solution

  • Most of the times, ![aThing aMethod] in Objective-C will translate to !aThing.aMethod in Swift.

    Also, no need to wrap the boolean condition in parenthesis anymore.

    if session == nil || !session.isValid {
    
    }