Swift Language Using Objective-C classes from Swift code


Example

If MyFramework contains Objective-C classes in its public headers (and the umbrella header), then import MyFramework is all that's necessary to use them from Swift.

Bridging headers

A bridging header makes additional Objective-C and C declarations visible to Swift code. When adding project files, Xcode may offer to create a bridging header automatically:

bridging header dialog

To create one manually, modify the Objective-C Bridging Header build setting:

enter image description here

Inside the bridging header, import whichever files are necessary to use from code:

// MyApp-Bridging-Header.h
#import "MyClass.h"  // allows code in this module to use MyClass

Generated Interface

Click the Related Items button (or press ⌃1), then select Generated Interface to see the Swift interface that will be generated from an Objective-C header.