[英]Swift class in Cocoa Touch Objective-C Framework
I'm trying to build a Cocoa Touch Framwork (XCode 6, obviously) with Objective-C and some Swift classes. 我正在尝试用Objective-C和一些Swift类构建一个Cocoa Touch Framwork(显然是XCode 6)。
I've successfully added Swift classes to regular projects (no framworks) before so I'm aware of the build settings required for this ( Embedded Content Contains Swift Code ). 我之前已经成功地将Swift类添加到常规项目(没有framworks),所以我知道这需要的构建设置( 嵌入式内容包含Swift代码 )。 Unfortunately, the framework project doesn't build the header file ( projectName-Swift.h ) and I'm not able to import the class and the Swift classes into any of my .m files. 不幸的是,框架项目没有构建头文件( projectName-Swift.h ),我无法将类和Swift类导入到我的任何.m文件中。
Does anybody know why this wouldn't work, and what build settings I need to change in order to make this work? 有谁知道为什么这不起作用,以及我需要改变哪些构建设置才能使其工作?
Finally found the answer; 终于找到了答案;
Within the frameworks the import statement for Swift files has to look as follows; 在框架内,Swift文件的import语句必须如下所示:
#import <ProjectName/ProjectName-Swift.h>
instead of 代替
#import "ProjectName-Swift.h"
Sometimes it helps to RTFM ( https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_82 ) 有时它对RTFM有帮助( https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_82 )
I've struggled with this for a while because I don't think the documentation is clear. 我已经挣扎了一段时间,因为我认为文档不清楚。 I have a slightly different project setup, and it's taken me a while to work this out so I thought I'd answer here. 我有一个稍微不同的项目设置,我需要一段时间来解决这个问题,所以我想我会在这里回答。
I have a project with name: MyProject In this project, I have a framework: MyFramwork 我有一个名为的项目:MyProject在这个项目中,我有一个框架:MyFramwork
I have a swift file in MyFramework which I want to import into an objective c file in MyFramework. 我在MyFramework中有一个swift文件,我想将其导入到MyFramework中的目标c文件中。
To do this, you need: 为此,您需要:
#import <MyFramework/MyFramework-Swift.h>
NOT 不
#import <MyProject/MyFramework-Swift.h>
Hope that helps someone. 希望能帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.