title: Objective-C @available guard AND'ed with more conditions
body: <p>Objective-C has an <a href="https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available" rel="noreferrer"><code>@available</code> expression</a> in XCode 9+ / LLVM 5+ that allows you to guard a block of code to at least a certain OS version so that it won't emit unguarded availability warnings if you use APIs that are only available on that OS version.</p>
  
  <p>The problem is that this availability guarding is that it only works if it's the sole expression in the condition of an <code>if</code>. If you use it in any other context, you get a warning:</p>
  
  <pre><code>@available does not guard availability here; use if (@available) instead
  </code></pre>
  
  <p>So for example, it doesn't work if you try to AND the availability check with other conditions in the <code>if</code>:</p>
  
  <pre><code>if (@available(iOS 11.0, *) &amp;&amp; some_condition) {
    // code to run when on iOS 11+ and some_condition is true
  } else {
    // code to run when on older iOS or some_condition is false
  }
  </code></pre>
  
  <p>Any code that uses iOS 11 APIs inside the <code>if</code> block or in <code>some_condition</code> still will generate unguarded availability warnings, even though it is guaranteed that those pieces of code can only be reached when on iOS 11+.</p>
  
  <p>I could turn it into two nested <code>if</code>s, but then the <code>else</code> code would have to be duplicated, which is bad (especially if it's lots of code):</p>
  
  <pre><code>if (@available(iOS 11.0, *)) {
    if (some_condition) {
      // code to run when on iOS 11+ and some_condition is true
    } else {
      // code to run when on older iOS or some_condition is false
    }
  } else {
    // code to run when on older iOS or some_condition is false
  }
  </code></pre>
  
  <p>I can avoid duplication by refactoring the <code>else</code> block code into an anonymous function, but that requires defining the <code>else</code> block before the <code>if</code>, which makes the code flow hard to follow:</p>
  
  <pre><code>void (^elseBlock)(void) = ^{
    // code to run when on older iOS or some_condition is false
  };
  
  if (@available(iOS 11.0, *)) {
    if (some_condition) {
      // code to run when on iOS 11+ and some_condition is true
    } else {
      elseBlock();
    }
  } else {
    elseBlock();
  }
  </code></pre>
  
  <p>Can anyone come up with a better solution?</p>