Swift-Bridge Header

This is a simple way to use both“Swift” and “Objective-C” in the same project. Now, I use swift in project but some frameworks or library are Objective-C. Apple offer easy method called “Bridge-Header” so I will show you: How to use “Brdge-Header” in your project. It very common and fast to understand.


In the example, I want to use AFNetwork that Objective-C framework into swift project. There are a little step and not difficulties. I will make it in step by step.

First, create “Header file” by Newfile -> source -> Header File

create “Header File”.

I create “Header” that header file’s name so there is Header.h in project. In “Header.h” write some code to import framework.

#ifndef Header_h
#define Header_h
#import <AFNetworking/AFNetworking.h>
#endif

Then, go to “PROJECT” and “build setting”. In search fill, enter “swift compiler”. In “Swift Compiler-Code Generation”, finding “Objective-C Bridging Header”. Now, it is empty.

Next, double click in this empty and write your path of Header file by [Project Name]/[Header File Name] such as “TestBridgeHeader/Header.h”.

When finished, enter and Objective-C Bridge Header isn’t empty.

In Objective-C Bridge Header, there is path header file’s name.

Finally, import framework in swift project and you can use all frameworks Objecttive-C that you import at header file in every where.

Import framework in swift project.

Congratulation!! you can use both swift and objective-c in the same project. I hope this story will help you so much(Ha Ha Ha~). Thank you for reading. Have a nice month in happy December.