Check for class existence in Swift

前端 未结 3 641
我寻月下人不归
我寻月下人不归 2021-02-05 05:50

I want to use NSURLQueryItem in my Swift iOS app. However, that class is only available since iOS 8, but my app should also run on iOS 7. How would I check for class existence i

3条回答
  •  不要未来只要你来
    2021-02-05 06:35

    Simplest way I know of

    if NSClassFromString("NSURLQueryItem") != nil {
        println("NSURLQueryItem exists")
    }else{
        println("NSURLQueryItem does not exists")
    }
    

提交回复
热议问题