我最近一直在努力将Swift添加到一个现有的项目中,以便在现实世界中进行尝试。

在向项目中添加Swift源文件时,我对获得“桥接头”没有任何问题,也就是说,Objective-C到Swift。

但是*-Swift.h头文件应该公开Swift类,无论是标记为@objc的类还是ObjC类的子类,都找不到:-(

在我的主应用程序代码(仍然是Objective-C)中,我没有看到任何关于如何使用我的新子类的具体说明,用Swift编写。

我是首席开发人员的应用程序有一个相当大的代码库(70.000行),所以一次性过渡它是不可能的。


当前回答

I had similar problem but my project was compiling before and suddenly got error after few files code change. It took me while to figure out why I am getting 'File not found' error for myproject-swift.h file. The code changes I had done had some errors. Xcode did not point put those error instead all time showing the 'File not found error'. Then got copy of previous version code and I compared with new code and merged file one by one. After each file merge complied the project to find the error. So bottom line is if you have error in your code Xcode may just display 'file not found error' for myproject-swift.h file. Most likely you have compilation error in your project. Clean those error and it will work.

其他回答

我有一个类似的问题,发现你只能添加

#进口“ProductModuleName-Swift.h”

到obj-c .m文件,而不是找到伞头的.h文件

I had similar problem but my project was compiling before and suddenly got error after few files code change. It took me while to figure out why I am getting 'File not found' error for myproject-swift.h file. The code changes I had done had some errors. Xcode did not point put those error instead all time showing the 'File not found error'. Then got copy of previous version code and I compared with new code and merged file one by one. After each file merge complied the project to find the error. So bottom line is if you have error in your code Xcode may just display 'file not found error' for myproject-swift.h file. Most likely you have compilation error in your project. Clean those error and it will work.

我也有同样的问题。在添加你的第一个Swift文件之前,似乎你必须调整设置(定义模块和产品模块名称)。

如果你之后这样做,即使你添加更多的Swift文件或删除Swift文件并创建一个新的Swift文件,“*-Swift.h”文件也不会为这个项目生成。

只是提醒那些在项目名称中使用“。”的人。对于Swift版本的桥接头文件,Xcode将用下划线“_”替换“。”。奇怪的是,生成的Bridging-Header.h不会用下划线替换句点。

例如,一个名为My的项目。项目将具有以下桥接头文件名。

Bridging-Header.h(自动生成)

My.Project-Bridging-Header.h

Swift.h

My_Project.h

我希望这能帮助那些像我一样用了大姨妈却被困住的人。该文件可以在以下位置找到。

麦金塔HD / \用户/用户/ Library /开发商Xcode DerivedData /我。Project-fntdulwpbhbbzdbyrkhanemcrfil /构建/ Intermediates构建Debug-iphonesimulator /我的项目。项目构建- DerivedSources。

当心

Jon

唯一重要的是:*

在目标中使用定义的“产品模块名”,后跟-Swift.h

#import <Product Module Name>-Swift.h

// in each ObjectiveC .m file having to use swift classes
// no matter in which swift files these classes sit.

无论“定义模块”参数设置为“是”或“否”,或“产品模块名称”项目未设置。

提醒:Swift类必须派生自NSObject或被标记为@objc属性,以便暴露给ObjectiveC / Foundation || Cocoa…