iosswiftmacrosavailability

Disable "is only available on iOS 11.0 or newer" in swift?


The problem is I want to check a solution which requires a variable declared in a class. But if I do it I should mark the whole class as @available(iOS 11.0, *) which causes a lot of changes in many other places.

So is it possible to disable it fully in one place at best? Or disable it temporarily (just to test new features without of significant changes and without changes of the minimum iOS version) at worst?


Solution

  • The best solution I found is to use properties:

    class SomeClass {
        private var _authSession: NSObject!;
        @available(iOS 11.0, *)
        var authSession: SFAuthenticationSession! {
            get {
                return _authSession as! SFAuthenticationSession
            }
            set(val) {
                _authSession = val
            }
        }
    }
    

    It is just an example so ! may be replaced with ? if it is necessary. In short - iOS forbids to declare variables with @available but allows to mark properties with this macro.