Why can't #available be use with the ternary condition operator?

For instance why can't I write:

aVisualEffectView.material = #available(OSX 10.14, *) ? .light : .toolTip

Is there a technical reason or style issue with the above?


#available is a "statement condition", meaning it's used in if, guard, and while statements because it affects the scope of the following body where the condition is true. This is like the if let x = optional or if case <pattern> = <value> syntax, which also don't currently work in ternaries. We could conceivably make it so that these conditions work in ternaries as well, and have the expect effect on the scope of the "true" arm of the ternary, but just haven't implemented this yet.


Thanks. Would such a change need a proposal?

Terms of Service

Privacy Policy

Cookie Policy