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

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

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