<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/making-objective-c-apis-unavailable-in-swift",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Making Objective-C APIs Unavailable in Swift"
}
-->

# Making Objective-C APIs Unavailable in Swift

Use the `NS_SWIFT_UNAVAILABLE` macro to prevent an API from being used in Swift.

## Overview

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 supersede 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_SWIFT_UNAVAILABLE` 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:

```occ
+ (instancetype)collectionWithValues:(NSArray *)values
                             forKeys:(NSArray<NSCopying> *)keys
NS_SWIFT_UNAVAILABLE("Use a dictionary literal instead.");
```

Attempting to call the `collectionWithValues:forKeys:` 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_UNAVAILABLE` macro. The macro behaves just like the `NS_SWIFT_UNAVAILABLE`
macro except that it doesn’t support the customizable error message and it restricts
compile-time access to the declaration in Objective-C code.

---

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)