Amit Thakur
Amit Thakur

Reputation: 1081

How to solve Bridiging header error in swift

Trying to call objective c code in swift code but it don't let me to do, it tell header file is missing.

Upvotes: 1

Views: 66

Answers (3)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71852

The easiest way to create an Objective-C bridging header and all the project settings to support it is to add any Objective-C file to your project.

Go to File\New\File…, select iOS\Source\Cocoa Touch Class and then click Next. Enter FakeObjectiveCClass as the Class name and choose NSObject as the subclass. Also, make sure the Language is set to Objective-C! Click Next, then Create.

When prompted Would you like to configure an Objective-C bridging header? select Yes.

You’ve successfully created an Objective-C bridging header. You can delete FakeObjectiveCClass.m and FakeObjectiveCClass.h from the project now, since you really just needed the bridging header.

Upvotes: 1

Vito Royeca
Vito Royeca

Reputation: 657

In Xcode, add a new class with Objective-C as the language. When prompted to create a bridging header file, click yes.

You will have a file added to your project named: YourProjectName-Bridging-Header.h.

Add all your imports to this file.

In your Swift classes, import the bridging-header file.

Upvotes: 0

Amit Thakur
Amit Thakur

Reputation: 1081

I got an solution for bridging-header.h file does not exit. Just want to share, hope it may help others too.

Follow below steps:-

First of all delete all header file if you have implemented any.
Add new header file from the ios templet. Hope you know how to add any new file, just follow in same manner.
Now go to the buid setting and there search for objective-c bridging header, simply put the header file name with .h extension too.

please see the image how to add the file name in objective-c Bridging Header enter image description here

Upvotes: 0

Related Questions