NS macro to customize API names for Swift.
- Swift Standard Library
If you want to import an Objective-C API into Swift with a different name, use the
NS macro. The macro preserves the Objective-C name for use with Objective-C code, so the API has appropriate names in each language.
You apply the
NS macro to an individual type, method, or function declaration in Objective-C. After applying the macro, the name you use in your Swift code will be what you've chosen by using the macro.
The example below renames a class and one of its properties:
Sandwich class and its
includes property are renamed to
is for Swift:
You use the
NS macro as a prefix for classes and protocols. For all other kinds of declaration—such as properties, enumeration cases, and type aliases—you use the macro as a suffix. The following example uses the macro as a suffix to rename an enumeration: