<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/renaming-objective-c-apis-for-swift",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Renaming Objective-C APIs for Swift"
}
-->

# Renaming Objective-C APIs for Swift

Use the `NS_SWIFT_NAME` macro to customize API names for Swift.

## Overview

If you want to import an Objective-C API into Swift with a different name, use the
`NS_SWIFT_NAME` 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_SWIFT_NAME` 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.

### Rename APIs

The example below renames a class and one of its properties:

```occ
NS_SWIFT_NAME(Sandwich.Preferences)
@interface SandwichPreferences : NSObject

@property BOOL includesCrust NS_SWIFT_NAME(isCrusty);

@end

@interface Sandwich : NSObject
@end
```

The `SandwichPreferences` class and its `includesCrust` property are renamed to `Sandwich.Preferences`
and `isCrusty` for Swift:

```swift
var preferences = Sandwich.Preferences()
preferences.isCrusty = true
```

You use the `NS_SWIFT_NAME` 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:

```occ
typedef NS_ENUM(NSInteger, SandwichBreadType) {
    brioche, pumpernickel, pretzel, focaccia
} NS_SWIFT_NAME(SandwichPreferences.BreadType);
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)