Sobes.tech
Junior — Middle

How is Objective-C code integrated into a Swift project?

sobes.tech AI

Answer from AI

To connect Objective-C code in a Swift project, a so-called Bridging Header is used — a special header file into which Objective-C headers are imported.

Steps:

  1. Create a Bridging Header (usually Xcode suggests creating it automatically when adding an Objective-C file to a Swift project).
  2. In this file, add #import "YourObjectiveCFile.h" for all necessary Objective-C headers.
  3. After that, Swift code can directly use classes and methods from Objective-C.

Example of a Bridging Header:

#import "MyObjectiveCClass.h"

Now in Swift:

let obj = MyObjectiveCClass()
obj.someMethod()

Thus, the Bridging Header serves as a bridge between Objective-C and Swift in a single project.

How is Objective-C code integrated into a Swift… - sobes.tech