0

In my Swift Project, I added a new cocoa Objective-C class (UIViewController), Xcode prompted me whether I want it to automatically generate an Objective-C bridging header file.

I am a bit confused because the generated file is ProductModuleName-Bridging-Header.h while, as per Apple documentation, I was waiting to get a ProductModuleName-Swift.h instead (In order to import Swift into Objective-C).

The ProductModuleName-Bridging-Header.h is mandatory in order to be able to import Objective-C from Swift, and not the inverse.

Any clarification on this?

Thanks

1 Answer 1

2

The behavior you describe is exactly correct. You're adding Obj-C to your Swift project, therefore Xcode offers to create a -Bridging-Header.h file which allows that imported Obj-C to be used in your Swift code. This is described in the documentation you linked under "Importing Objective-C into Swift".

Unlike the bridging header, the -Swift.h file doesn't appear in your file hierachy, and is not something you see or edit. It's generated and managed entirely by Xcode during the build process. You simply import into .m files when needed.

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

1 Comment

Ah so it's a hidden file? I think Apple should have added this to the documentation.

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.