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


if let popupbutton = result?.control as? nspopupbutto {     if popupbutton.numberofitems <= 1 {         // blahblah     } } 

i want avoid double nested if.

if let popupbutton = result?.control as? nspopupbutton && popupbutton.numberofitems <= 1 {} 

but unresolved identifier compiler error if that.

is there way make condition on 1 line? or because i'm using optional binding, forced make nested if here?

you can way:

if let popupbutton = result?.control as? nspopupbutton, popupbutton.numberofitems <= 1 {     //blahblah } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -