NS macro to prevent an API from being used in Swift.
If parts of an Objective-C API aren't suitable for Swift, you can make those parts unavailable in Swift. You make part of an API unavailable in Swift as part of introducing new Swift APIs that supercede parts of the existing Objective-C API. For example, you might replace an Objective-C constant with a Swift constant that's nested inside a containing Swift type.
Prevent an Objective-C API from Being Imported
To prevent a declaration in an Objective-C API from being imported, pass a single parameter to the
NS macro. The parameter indicates what a developer using Swift should do instead of using the part of the API you're making unavailable.
In this example, an Objective-C class that provides a convenience initializer that takes variadic arguments for key-value pairs suggests using a dictionary literal instead:
Attempting to call the
collection method in Swift results in a compiler error.
Make an API Unavailable in Both Languages
To make an Objective-C declaration unavailable at compile time in both Swift and Objective-C, use the
NS macro. The macro behaves just like the
NS macro except that it doesn't support the customizable error message and it restricts compile-time access to the declaration in Objective-C code.