16

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?

3
  • 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? Commented Sep 8, 2015 at 8:19
  • 1
    I had a similar problem. My (slightly better?) hack was to add the missing import to the bridging header. Commented Nov 27, 2015 at 19:52
  • See stackoverflow.com/questions/52400250 Commented Jun 9, 2020 at 13:55

2 Answers 2

1

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.

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

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.