问题
I've got a project using the Swift generated Bridging Header and have the project set up correctly (no spaces in Names, Uses Modules, pre-declaring Swift classes in my .mm file, Deleting derived data, doing a clean rebuild etc...). The Bridging Header is being generated fine, but the automatically generated -Swift.h has errors in it. What's even worse, those errors are on the generated (in project creation - Swift) versions of AppDelegate and ViewController which would normally compile fine. The errors in the -Swift.h are:
@interface AppDelegate : UIResponder <UIApplicationDelegate>
>> Cannot find interface declaration for 'UIResponder', superclass of 'AppDelegate'
>> Cannot find protocol declaration for 'UIApplicationDelegate'@interface ViewController : UIViewController
>> Cannot find interface declaration for 'UIViewController', superclass of 'ViewController'
I've searched Stack Overflow and the net and can't find any answer that addresses this particular issue. Has anyone else had this? Or, is there a way I can mark my AppDelegate and ViewController classes so Xcode doesn't try and create Objective-C stubs for those Swift classes as I don't actually need them?
回答1:
Just add
#import <UIKit/UIKit.h>
before
#import <YourProject-Swift.h>
in .mm file. for me it helps.
回答2:
I had same problem and discovered that..
-Swift.h only work best with Objective-C, not Objective-C++ (.mm)
So I use the Objective-C class to connect with the Swift class. Also You can always load your Objective-C++ class in your Objective-C class.
回答3:
Try to import UIKit/UIKit.h into bridging header file.
来源:https://stackoverflow.com/questions/29285930/swift-objective-c-project-generated-swift-h-error-cannot-find-interface-d