[英]How to work with Swift file in Objective-C?
I want to use one third party library which is written in Swift but I am working in Objective-C environment. 我想使用一个用Swift编写的第三方库,但是我在Objective-C环境中工作。 How to do that?
怎么做? Until now what I have done is:
到目前为止,我所做的是:
defines Modules
no to yes
in both. defines Modules
否” defines Modules
为“ yes
。 $(PRODUCT_NAME:c99extidentifier)
. $(PRODUCT_NAME:c99extidentifier)
。 I have tried with my project name also. Now I am getting plenty of errors like below: 现在,我收到很多错误,如下所示:
pDatePicker.swift:50:9: Consecutive declarations on a line must be separated by ';'
pDatePicker.swift:50:9:行上的连续声明必须以';'分隔
and 和
Ambiguous use of 'open'.
歧义使用“开放”。
I am getting errors around 50 to 60 same as above errors. 我收到与上述错误相同的大约50到60的错误。 Where is my mistake?
我的错误在哪里? Can anybody help me?
有谁能够帮助我?
Make sure, that your swift version in settings is the same as this lib uses; 确保设置中的快速版本与此lib使用的版本相同; if not, try to translate it by yourself, or set Use Legacy Swift Version to YES
如果不是,请尝试自行翻译,或将“使用旧版Swift版本”设置为“是”
Are you able to see projectName-Swift.h file in your project ? 您可以在项目中看到projectName-Swift.h文件吗?
Demo Example is available on github. 演示示例可在github上找到。
https://github.com/hasyapanchasara/UsingSwiftInObjectiveC https://github.com/hasyapanchasara/UsingSwiftInObjectiveC
If yes then, Hope you have imported #import "projectName-Swift.h" in Objectice C .m file ? 如果是,那么,希望您已在Objectice C .m文件中导入#import“ projectName-Swift.h”吗?
#import "projectName-Swift.h"
Then only you would be able to access objective c files in swift code. 这样,只有您才能以快速代码访问目标c文件。
Refer 参考
https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
if there is problem with that path than bridging will not work properly , that why when you compile #import "projectName-Swift.h"
is not getting generate. 如果该路径存在问题,则桥接将无法正常工作,这就是为什么在编译
#import "projectName-Swift.h"
未生成的原因。
Download above sample project. 下载以上示例项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.