I imported an Obj-C file into my swift project and Xcode automatically prompted me to create a bridging header file as expected. However, I deleted both the files (moved to trash) to make some changes, but when i try to import the Obj-C file once again, the prompt doesn't come up anymore. What is the reason? I even tested this same scenario in another project, It seems once I delete Xcode's auto created bridging header, It won't bring the prompt up again another time. Why is this?
To create an Objective-C bridging header file, all you need to do is drag some Objective-C code into your Swift project – Xcode should prompt you with the message "Would you like to configure an Objective-C bridging header?" Click "Creating Bridging Header" and you'll see a file called YourProjectName-Bridging-Header.
Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File. Edit the bridging header to expose your Objective-C code to your Swift code: In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.
The reason of your issue is, the Xcode build settings still holds the path to auto generated Bridging Header file. You cannot get any build errors because of the header file (ProjectName-Bridging-Header.h)
still exist in your project directory.
How to resolve:
Click on your project target, Go to Build Settings tab (choose all instead of basic), search for Bridging Header. You can see the Xcode generated path entry. Select it and click on delete button.
Also, make sure to delete the Xcode auto generated bridging header file (ProjectName-Bridging-Header.h)
from your Xcode project directory.
Now, try to import the Obj-C file once again. You can see the prompt to create a bridging header file as expected.
File -> New File -> Header File
Save it as a YourApp-Bridging-Header
Than go to Build Settings, find "Objective-C Bridging Header" (as previously guys told) and pass way to your Bridging Header as: YourApp/YourApp-Bridging-Header.h Where 'YourApp/' is a name of app. It could contain white space, for example 'Your App/'.
In my case in xCode 7.3.1 it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With