Objective-C @available guard AND'ed with more conditions

前端 未结 8 1321
眼角桃花
眼角桃花 2021-01-01 11:17

Objective-C has an @available expression 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 ava

8条回答
  •  不思量自难忘°
    2021-01-01 11:43

    The way I came up with that seems to change the layout of the code the least is:

    do {
      if (@available(iOS 11.0, *)) {
        if (some_condition) {
          // code to run when on iOS 11+ and some_condition is true
          break;
        }
      }
      // code to run when on older iOS or some_condition is false
    } while (0);
    

    which is still ugly.

提交回复
热议问题