How add Objective-C files in a Swift Cocoa Touch Framework

Cocoa Touch Framework

This post is a tip to know how add third libs or files in Objective-C in a Swift Cocoa Touch Framework projects.

Are three simple steps, so let’s begin!

Step 1

The first thing to do is add the Objective-C files inside the project (could be dragging and dropping).

Drag and Drop the Objective-C Files

Step 2

After put the files in the project is necessary to go in Project Target -> Build Phases -> Headers.

There will see all ‘.h’ files inside the Projects tab. You must drag and drop all files to Public tab. See bellow:

Files on Project Tab
Files dragged to Public Tab

Now all ‘.h’ files are publics in your project. To make them usable is necessary do one more thing.

Step 3

The last thing to do is import them in the Bridge file (is created automatically by Xcode).

The Bridge is usually is the name of the project with the ‘.h’ extension.

Note: If the project is called MyProject, the name of the Bridge file will be MyProject.h.

Open the Bridge file and bellow the import <UIKit/UIKit.h> add all Objective-C headers in the Project.

#import <UIKit/UIKit.h>
#import "SomeImportedFile.h"

Added Objective-C headers on Bridge file

Done! Now all project is available to use those Objective-C files in Swift files.

Thanks!