Wrap availability check in compilation condition

Currently we can't do availability check conditionally:

#if USE_COMBINE
// use Apple's Combine
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) // Error: Expected expression
#else
// use open-source Combine
#endif
struct MyPublisher: Publisher {}

It's also useful to enable property wrapper conditionally:

struct A {
    #if ENABLE_FOO
    @Foo
    #endif
    var a: Int
}

Can we lift this restriction?

4 Likes

Sounds like a good idea to me! I think it should definitely apply to all attributes though, not just @available.

Terms of Service

Privacy Policy

Cookie Policy