Dmitry Katkevich
Dmitry Katkevich

Reputation: 923

Make some API unavailable starting from particular iOS version in Objective-C

In Swift we can write something like this:

@available(iOS, introduced: 14.0, obsoleted: 15.0)
@objc extension Foo {
func foo(_ arg: AnyObject) {}
}

I believe that this means "api will only be available for ios versions 14.0 .. 14.9.9"

In Objective-C I want to write this:

@interface Foo (FooCategory)
- (void) foo:(id)someId API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(ios(15.0));
@end

But this doesn't work coz API_UNAVAILABLE only accepts platform without specific version.

How can I restrict some API to the exact version of a specific platform?

Upvotes: 1

Views: 486

Answers (1)

DarkDust
DarkDust

Reputation: 92394

The name of the macro you're looking for is API_DEPRECATED.

@interface Foo (FooCategory)
- (void) foo:(id)someId API_DEPRECATED("Your message", ios(14.0, 15.0));
@end

Its documentation looks like this:

    /*
     * API Deprecations
     *
     * Use to specify the release that a particular API became unavailable.
     *
     * Platform names:
     *   macos, ios, tvos, watchos
     *
     * Examples:
     *
     *    API_DEPRECATED("No longer supported", macos(10.4, 10.8))
     *    API_DEPRECATED("No longer supported", macos(10.4, 10.8), ios(2.0, 3.0), watchos(2.0, 3.0), tvos(9.0, 10.0))
     *
     *    API_DEPRECATED_WITH_REPLACEMENT("-setName:", tvos(10.0, 10.4), ios(9.0, 10.0))
     *    API_DEPRECATED_WITH_REPLACEMENT("SomeClassName", macos(10.4, 10.6), watchos(2.0, 3.0))
     */

Upvotes: 0

Related Questions