Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Cannot find interface declaration' in auto-generated Swift bridging header

My current project contains both Swift and Objective-C code. Both types of source file use code from the other language. When I do a full clean and recompile, I get errors on almost every single Swift class declaration in Module-Swift.h, of the form:

Cannot find interface declaration for 'UIViewController', superclass of 'CustomViewController'

My symptoms are similar to this question, in similar circumstances to this question. In other words:

  • Module-Bridging_Header.h imports my Objective-C header, Class.h
  • The implementation file Class.m imports the Swift header, Module-Swift.h

If I follow the approach in the ansewrs to this question, I can resolve the error by adding the following file, and importing that in place of Module-Swift.h:

//
//  Module-Swift-Fixed.h
//  Module
//

#ifndef Module_Swift_Fixed_h
#define Module_Swift_Fixed_h

#import <Foundation/Foundation.h>

#import <CoreData/CoreData.h>
#import <UIKit/UIKit.h>

#import "Module-Swift.h"

#endif /* Module_Swift_Fixed_h */

This seems like a horrible hack. Am I missing some proper way to achieve this in Xcode?

like image 838
sapi Avatar asked Jan 20 '26 01:01

sapi


2 Answers

In Obj-C files, you need to import the swift module (with #import "Module-Swift.h").

Do this only in the files where you are going to use types defined in your Swift module.

like image 177
Eneko Alonso Avatar answered Jan 21 '26 18:01

Eneko Alonso


I cannot express how much this helped me out. Unfortunately, we have to use the hack that OP used when using mixed objc and Swift modules. If it's possible for your use case, you should try to separate the modules, but if that isn't possible use the hack.

like image 37
milkbox Avatar answered Jan 21 '26 16:01

milkbox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!