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

前端 未结 8 1309
眼角桃花
眼角桃花 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:42

    You could also simply use a flag:

    BOOL doit = FALSE;
    
    if (@available(iOS 11.0, *)) {
      if (some_condition) {
        doit = TRUE;
      }
    }
    
    if (doit) {
      // 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
    }
    

提交回复
热议问题