简体   繁体   English

如何将用Swift编写的Cocoa Touch Framework导入.pch文件?

[英]How to import a Cocoa Touch Framework written in Swift to a .pch file?

I created a Swift framework which I want to import in every class I make in my Swift project. 我创建了一个Swift框架,我想在我在Swift项目中创建的每个类中导入它。 I don't want to have to type the import statement manually, and everywhere. 我不想手动和任何地方import语句。 How can I do this? 我怎样才能做到这一点?

In Objective-C this would be the same as putting one #import statement in the pre-compiled header (.pch file). 在Objective-C中,这与在预编译头(.pch文件)中放入一个#import语句相同。

What I tried 我尝试了什么

  • Create a new Xcode project with the Cocoa Touch Framework template, write all my code in Swift. 使用Cocoa Touch Framework模板创建一个新的Xcode项目,在Swift中编写我的所有代码。
  • All my extensions and methods in the framework have the public keyword. 我在框架中的所有扩展和方法都有public关键字。
  • Added the framework's .xcodeproj to my app's Xcode project. 将框架的.xcodeproj添加到我的应用程序的Xcode项目中。
  • Add the .framework in Target Dependencies. 在Tar​​get Dependencies中添加.framework
  • Create a .pch file in my app project (also written in Swift). 在我的应用程序项目中创建一个.pch文件(也用Swift编写)。
  • Wrote <FrameworkName/FrameworkName.h> in the .pch file. 在.pch文件中写了<FrameworkName/FrameworkName.h> This doesn't solve the problem, and kinda doesn't make sense, because I don't really import anything in the FrameworkName.h inside the framework project. 这并没有解决问题,有点没有意义,因为我没有在框架项目中的FrameworkName.h真正导入任何东西。

You can add .pch file manually and then you can import your common files in your .pch file. 您可以手动添加.pch文件,然后可以在.pch文件中导入公共文件。 for more info see below link 有关更多信息,请参阅以下链接

Add new .pch file 添加新的.pch文件

see in this image 看到这张图片 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM