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:
我有一个项目使用Swift生成的桥接头,并正确地设置了项目(名称中没有空格,使用模块,在我的.mm文件中预先声明Swift类,删除派生数据,进行干净的重新构建等等)。生成的桥接头很好,但是自动生成的-Swift。h有误差。更糟糕的是,这些错误出现在AppDelegate和ViewController的生成版本上(在项目创建- Swift中),这些版本通常会编译得很好。swift中的错误。h:
-
@interface AppDelegate : UIResponder <UIApplicationDelegate>
>> Cannot find interface declaration for 'UIResponder', superclass of 'AppDelegate'
>> Cannot find protocol declaration for 'UIApplicationDelegate' -
UIResponder
>>无法找到'UIResponder'的接口声明,'AppDelegate' >>的超类无法找到'UIApplicationDelegate'的协议声明 -
@interface ViewController : UIViewController
>> Cannot find interface declaration for 'UIViewController', superclass of 'ViewController' - @interface ViewController: UIViewController >>找不到'UIViewController'的接口声明'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?
我搜索了Stack Overflow和net,但是找不到任何解决这个问题的答案。有人有这个吗?或者,有没有一种方法可以标记AppDelegate和ViewController类,这样Xcode就不会尝试为这些Swift类创建Objective-C存根因为我实际上并不需要它们?
3 个解决方案
#1
5
I had same problem and discovered that..
我也有同样的问题,我发现…
-Swift.h only work best with Objective-C, not Objective-C++ (.mm)
斯威夫特。h只对Objective-C有效,而不是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.
所以我使用Objective-C类来连接Swift类。您还可以在Objective-C类中加载您的objective - c++类。
#2
5
Just add
只需添加
#import <UIKit/UIKit.h>
before
之前
#import <YourProject-Swift.h>
in .mm file. for me it helps.
在功能文件中。对我来说,这有帮助。
#3
1
Try to import UIKit/UIKit.h into bridging header file.
尝试导入UIKit / UIKit。将h转换为桥接头文件。
#1
5
I had same problem and discovered that..
我也有同样的问题,我发现…
-Swift.h only work best with Objective-C, not Objective-C++ (.mm)
斯威夫特。h只对Objective-C有效,而不是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.
所以我使用Objective-C类来连接Swift类。您还可以在Objective-C类中加载您的objective - c++类。
#2
5
Just add
只需添加
#import <UIKit/UIKit.h>
before
之前
#import <YourProject-Swift.h>
in .mm file. for me it helps.
在功能文件中。对我来说,这有帮助。
#3
1
Try to import UIKit/UIKit.h into bridging header file.
尝试导入UIKit / UIKit。将h转换为桥接头文件。