Negate #available statement

后端 未结 5 638
南旧
南旧 2020-12-09 07:49

I want to execute a code block only on devices running with an OS older than iOS8. I can\'t do:

if #available(iOS 8.0, *) == false {
    doFoo()         


        
5条回答
  •  无人及你
    2020-12-09 08:45

    simple way to check is to create the function

    func isNewFeatureAvailable() -> Bool {
        if #available(iOS 9, *) {
            return true
        } else {
            return false
        }
    }
    

    Use:

    if isNewFeatureAvailable() {
        // use new api
    } else {
        // use old api
    }
    

    OR just use inline

    if #available(iOS 9, *) {
       // use new api
    } else {
       // use old api
    }
    

提交回复
热议问题