13
votes

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?

1
Are you in Swift 2.0? It does not seem to be a problem with Xcode 7. If you are, can you post the project? - SwiftArchitect
I had a similar problem. My (slightly better?) hack was to add the missing import to the bridging header. - Bjorn Roche

1 Answers

0
votes

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.