We know that we can use an if let
statement as a shorthand to check for an optional nil then unwrap.
However, I want to combine that with another expression
Max's answer is correct and one way of doing this. Notice though that when written this way:
if let a = someOptional where someBool { }
The someOptional
expression will be resolved first. If it fails then the someBool
expression will not be evaluated (short-circuit evaluation, as you'd expect).
If you want to write this the other way around it can be done like so:
if someBool, let a = someOptional { }
In this case someBool
is evaluated first, and only if it evaluates to true is the someOptional
expression evaluated.