Xcode Myprojectname-Bridging-Header.H Does Not Exist

Bridging-Header Does not exists

In your build settings, give a complete address to your bridging header instead of testLogin/testLogin-Bridging-Header.h

myProjectName-Swift.h not found after clean build

You must not use #import "ProjectName-Swift.h" in the header files.

If you need Swift classes or protocols in the Obj-C code, you may forward declare them in the related Obj-C header. Here's more information about that:

When declarations in an Objective-C header file refer to a Swift class or protocol that comes from the same target, importing the generated header creates a cyclical reference. To avoid this, use a forward declaration of the Swift class or protocol to reference it in an Objective-C interface.

// MyObjcClass.h
@class MySwiftClass;
@protocol MySwiftProtocol;

@interface MyObjcClass : NSObject
- (MySwiftClass *)returnSwiftClassInstance;
- (id <MySwiftProtocol>)returnInstanceAdoptingSwiftProtocol;
// ...
@end

Also, please note, you may have issues with importing Swift Enums and Protocols and Classes into ObjC, so you may need to explicitly define items which you want to be available to ObjC code with @objc keyword.

And you won't be able to use Swift structs in Obj-C.

Swift Bridging-Header.h file not allowing me to instantiate objective-c classes in .swift files

You need to add it to your target's build settings:

  1. In Xcode, if you go into the build settings for your target, and scroll all the way down you'll find a "Swift Compiler - Code Generation" section.

  2. Set "Objective-C Bridging Header" to <#PROJECT_NAME>-Bridging-Header.h

  3. I'm not sure of the correct value for "Install Objective-C Compatibility Header", but it's a yes/no, so you can toggle that if it doesn't work at first.

How do I create an Objective-C bridging header?

You have to create a new objective c class:

You select New File

then

select cocoa touch class

then you name it and specify as objective-c class at language

select objective-c as language

then you select your directory and hit create. At this point xcode is going to ask you whether or not you want to create bridging header. Yep do it.

Sample Image

And at the end it should look more or less like this at your project.

Job done

hope that helps you.



Related Topics



Leave a reply



Submit