Bridging Header doesn't seem to include my Swift class

I think have done everything by the book.

I added a small Swift file to my Objective-C project. This is code in the project, not in a framework, so I did not use the public keyword:

import Foundation

@objc TestClass: NSObject {
    @objc init(){}
}

Adding this file prompted creating a bridging header and it should have added TestClass into it.

I added the import to the Objective-C .m file. This didn't produce an error so the file must be there:

#import "SoftServePro-Bridging-Header.h"

I made a property for an instance of the class in the .h file:

@property(nonatomic,strong) TestClass *test;

I cleaned the project and did one compile for the precompiler to populate the bridging header.

I have set Defines Module to Yes in Build Settings -> Packaging.

I added a line in the .m code to create a TestClass:

self.test=[[TestClass alloc]init];

And for my trouble I get the error message

Now, this looks to me like TestClass is not in my bridging header because if it were it should know exactly what TestClass is, not just consider it a forward declaration.

I haven't figured out any way to look at the actual contents of the bridging header after precompile, so I don't know if TestClass is there or not.

The ONLY thing that I have not followed is that the documentation I have read says to put the bridging header in the same folder as the .xcodeproj file, but Xcode put it in with all the source code files (one folder down) and who am I to argue with Xcode??

Answered by DTS Engineer in 879456022

This is confusing. There are different types of ‘bridging header’. The actual bridging header lets you call Objective-C from Swift, but there’s another header that you use to call Swift from Objective-C. I believe you’re looking for the latter. If so, I have a step-by-step example of this in this post.

I just retested this with Xcode 26.3 and it continues to work as described.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I forgot to mention that I also added TestClass as an @class in the .h file:

@class SSPMasterViewController,iMag,TestClass;

This is confusing. There are different types of ‘bridging header’. The actual bridging header lets you call Objective-C from Swift, but there’s another header that you use to call Swift from Objective-C. I believe you’re looking for the latter. If so, I have a step-by-step example of this in this post.

I just retested this with Xcode 26.3 and it continues to work as described.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Bridging Header doesn't seem to include my Swift class
 
 
Q