Swift BridgingHeader file – iOS 10 Minute Quick Hackby Applied Informatics
When writing Swift you will eventually run into the situation where you need to include Obj-C based code libraries, lucky for us, Apple has made it super easy by using what is called a “Bridging Header” file.
Here is how you create it,
- Create a new “Header File” file. In XCode this is done by going to “File > New > New File > iOS > Header File”
- Add the module you need to import, for example to import CommonCrypto library you would add “#import <CommonCrypto/CommonDigest.h>”
- Add the file to your Build Settings under the “Swift Compiler – Code Generation” section using the name “Objective-C Bridging Header” and point it to the file created in step 1.
Your file should look something like this.
// Created by Nickolas Whiting on 11/9/15.
// Copyright © 2015 Applied Informatics. All rights reserved.
And your build settings should include something like this,
Thats it, you are done!
This is part of our iOS 10 Minute Quick Hack series. Stay tuned for more!