mardi 25 juillet 2017

Is it possible to use the variable from an optional binding within the same conditional statement?

if let popupButton = result?.control as? NSPopUpButton 
    if popupButton.numberOfItems <= 1 {
        // blahblah
    }
}

I want to avoid the double nested if.

if let popupButton = result?.control as? NSPopUpButton && popupButton.numberOfItems <= 1 {}

but I get the unresolved identifier compiler error if I do that.

Is there any way to make this condition on one line? Or because I'm using an optional binding, am I forced to make a nested if here?

Aucun commentaire:

Enregistrer un commentaire