Reputation: 10224
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
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?
Upvotes: 16
Views: 2474
Reputation: 113
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.
Upvotes: 1
Reputation: 19722
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.
Upvotes: 1