Swift bridging header file won't work with use_frameworks
A) Create a Bridging Header file named
"ProjectName-Bridging-Header.h" in the root folder of your project.
B) Go to the project build settings and set the following values:
- "Install objective-c compatibility header" : YES
- "Objective-C Bridging Header" : path of your bridging header (e.g. "ProjectName/ProjectName-Bridging-Header.h"
After that you can use the header file to import all your ObjectiveC files which you want use within swift code.
NOTE: if required set the path as a recursive both in the resource headers and the Swift compiler search section.
If using Cocoapods and use_frameworks!, should I use Obj-C Bridging Header?
Short answer: yes.
It has nothing to do with use_frameworks!
, it has to do with exposing your Obj-C
pods to Swift.
See examples:
- https://stackoverflow.com/a/31742131/218152
- https://stackoverflow.com/a/31777069/218152
Getting file not found in Bridging Header when importing Objective-C frameworks into Swift project
Found a solution:
- The "Objective-C Bridging Header" setting (aka
SWIFT_OBJC_BRIDGING_HEADER
) must be set at the Target level, and NOT the Project level. Be sure to delete the setting value at the Project level.
(to me, it seems like an Xcode bug, since I don't know why it fixes it).
Bridging-header works, but imports are not working?
The answer is to import them like this in your bridging header:
#import "NBPhoneNumberUtil.h"
#import "NBPhoneNumber.h"
The procedure that I used to test this is written below.
Create a new Xcode project
I used the Single View Application template for Objective-C.
Create Podfile and Install
Podfile:
source 'https://github.com/CocoaPods/Specs.git'
pod 'libPhoneNumber-iOS', '~> 0.8'
Install:
$ pod install
Create a Swift file
At this point a bridging header file was created by Xcode.
I added the imports into the bridging header using:
#import "NBPhoneNumberUtil.h"
#import "NBPhoneNumber.h"
In the Swift file, I wrote:
class Test {
func test() {
let util = NBPhoneNumberUtil()
}
}
The project compiled without errors.
Related Topics
iOS Swift App with More Photos: Performance and Storage Suggestions
Cannot Access Appdelegate While Testing Xcode Project
Ios-Charts How to Put Uiimage Beside a Point
Stream Data from Network in Avaudioengine, Is It Possible
iOS 3Des with Ecb Return Half Correct Data
iOS Swift Remove Uitableview Cell Separator Space
Required Initializers for a Subclass of Uiviewcontroller
Could Not Cast Value of Type 'Nsnull' (0X10Aa1B600) to 'Nsstring' (0X10B4Dab48)
Swift How to Add Background Color Just Around Text in a Label
How to Design an Uiscrollview in Storyboard
Uitextfield Starting Cursor Position Is Wrong
Why Is Uisearchcontroller Changing the Navigation Bar Colors
How to Update a Swiftui View State from Outside (Uiviewcontroller for Example)
Swift - Set Delegate for Singleton
How to Add Two or More Buttons to Annotationview: Mkannotationview
Scroll All the Way Down to the Bottom of Uitableview
How to Send Request from iOS (Swift) to Dialogflow V2 API Without Cloud Functions