How to import a 3rd party framework into a Swift project

One day you’ll need to set up, let’s say, a mobile analytics system or a crash reports sender in your app. They are all useful, but some of them require you to import their framework into your Xcode project. Problem is, they’re now all written not using Swift Programming Language. In this little article I’ll tell you how to properly import a framework into your project.

I’ll show how to do it by importing a PLCrashReporter framework into an iOS application, but the process is absolutely the same for a Mac app and/or any other framework, for example Crashlytics, or any framework for a mobile analytics system.

Step 1.

Drag and drop the framework into your Xcode project. Check Copy items if needed.

Step 2.

Now we need to let Xcode know where to search for framework’s headers.
Select your project in the Project Navigator, then select your target in Targets menu.
Select Build Settings tab on the top.
Locate Header Search Paths (you can use search field on the top of course) and double click on its value.
Add a new line here by clicking plus (+) button.
Now you need to write here the path to the new framework’s headers.
For example, if my CrashReporter.framework is located in the same directory in which .xcodeproj file of my project is located, so I write this:


$(PROJECT_DIR) keyword is a nice thing that obviously represents project’s directory. It’s not recommended to write a full path to it (for example, Users/username/Documents/ProjectName), because there will be problems if you try to move the project or send it to someone.

And yes, you can double click on the framework to see its contents. Don’t worry if Headers folder is an alias. You shouldn’t care.

Step 3.

Add a Bridging Header.
We need to tell Swift that here’s some stuff which isn’t written in Swift so it’ll see it.
Select FileNew — File… or just press ⌘N, select Source on the left (doesn’t matter if it’s under OS X or iOS) and select Header File. Name the file "Projectname-Bridging-Header.h" where "Projectname" is your project’s name obviously. For example, if I’d want to create a bridging header in my Timerange app, I’d write "Timerange-Bridging-Header.h".

Go to this new header and import all headers from the framework that you’ll use. If it’s a crash reporter or mobile analytics system framework, then there’s probably one main header that you should import. For example, in PLCrashReporter framework there’s one main header, which is CrashReporter.h, so I only import this one:

#import "CrashReporter.h"

Step 4.

Last thing we need to do here is to tell Xcode about our new bridging header.
Go to Build Settings we visited before, locate Objective-C Bridging Header line and double click on it’s value.
My bridging header is located in project directory, so I write


That’s it! Now Swift will see new classes and functions, and autocompletion will work just fine. If not, build the project by pressing ⌘B, then try again.
Notice how Xcode automatically translates the syntax of framework’s language into Swift language. Sweet!

6 replies to “How to import a 3rd party framework into a Swift project”

    1. Just use


      if you’re doing step 4. You can’t just use ScanCard instead of a $(PROJECT_DIR), because the whole string needs to be a full path to the file.

  1. I have made FMDB framework, In that i have used sqlite.h file, when i used FMDB frame in my project then o am getting Non-moduler header can’t be use error. How can i resolve it?

    I am trying to resolve issue as u suggested but didn’t resolve it. Please help to resolve issue.

Leave a Reply

Your email address will not be published. Required fields are marked *