Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode not automatically creating bridging header?

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?

like image 372
John Durand Avatar asked Jul 30 '15 06:07

John Durand


People also ask

How do I create a bridging header in Xcode?

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.

How do I create a Swift 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.


2 Answers

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.

enter image description here

like image 153
Shamsudheen TK Avatar answered Oct 03 '22 15:10

Shamsudheen TK


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

like image 25
Iulian Nikolaiev Avatar answered Oct 03 '22 17:10

Iulian Nikolaiev