1

I'm currently working with Objective-C project, and i'm using some swift files in that so created bridge header like APPNAME-Swift.h. and i'm able to import in objective-C classes. But here my problem is i need to import objective-c class in swift file.

here is example:

Objective-C project>drag and drop swift files ClassA.swift, ClassB.swift into project and created bridge. Now in objective-C class i'm able to use swift classes in objective-c classes like below Appdelegate.h i imported #import "<#YourProjectName#>-Swift.h"

now i need to import Appdelegate.h in ClassB.swift.

Please Help me on it

1 Answer 1

2

You don't need to create the file "APPNAME-Swift.h" in your project, it will be generated automatically during build and you should not try to modify this file. You can create bridging header for your project but I guess You don't have a problem with it. I just recommend you to rename your bridging header, because I guess that the generated file "APPNAME-Swift.h" has the same name as your bridging header, that's why you have a problem.

After you will rename your bridging header change your build settings. You will need to change a string at Build Settings -> Objective-C Bridging Header (see attached image for more information):

Setup of bridging headers

If you want to change name of the file "APPNAME-Swift.h" you need also modify your build settings. You can do it at Build Settings -> Objective C Generated Interface Header Name (see attached image for more information):

Setup of the Objective C interface file

In your bridging header add the following line:

#import "MyObjectiveCClass.h"

And after that you will be able to use class MyObjectiveCClass (Objective-C) in your Swift code (if file "MyObjectiveCClass.h" contains a class called "MyObjectiveCClass").

All settings provided for Xcode 9.2.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for response i agree with you. its generated bridge header and i am able to use swift classes in objective-C, but i need to use objetive-c class in swift file as well
@BoosaRamesh What is name of your bridging header? Or maybe you use different headers for each target?
ProjectName/ProjectName-Bridging-Header.h, its generated automatically after drag and drop swift classes in objective-C project. i am able to use all swift classes in my project. but here the problem is i need import on of objective class like app delegate in swift class. i couldnt import
@BoosaRamesh Could you please add code from your bridging header to this question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.