将静态库目标转换为Xcode项目中的框架目标 [英] Convert a static library target into a framework target in an Xcode project

查看:152
本文介绍了将静态库目标转换为Xcode项目中的框架目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xcode项目,它生成一个静态库。我的团队计划在Swift中进行所有新开发。 无法将Swift文件添加到静态库项目。我们正在放弃对iOS 7的支持,因此现在可以在我们的iOS应用程序中包含框架。因此,我打算将我的静态库项目转换为框架项目。

I have a an Xcode project which produces a static library. My team plans all new development in Swift. It is not possible to add Swift files to the static library project. We are dropping support for iOS 7, so it is now possible to include frameworks in our iOS app. Therefore, I intend to convert my static library project to a framework project.

我看过,但我找不到任何有关如何执行此转换的工具或建议。静态库很大(超过100个.m文件)。

I have looked but I cannot find any tools or advice for how to perform this conversion. The static library is large (more than 100 .m files).

我希望得到比创建新的并行框架目标更好的答案。我试过两次。第一次作为一个快速的目标,但我无法轻松导入所有的Objective C文件。接下来,作为Objective C目标,但不再有.pch。

I'm hoping for a better answer than create a new parallel framework target. I've attempted this twice. The first time as a swift target, but I wasn't able to easily import all the Objective C files. Next, as an Objective C target, but there is no .pch anymore.

推荐答案

转换静态/动态链接框架静态链接库,

To convert the static/dynamic linked framework from static linked library,


  1. 在现有的静态链接库项目中添加一个新的cocoa touch框架作为TARGET。

  2. 在Build Phases中,将所有.m,.mm,.c,.cpp,.metal等添加到静态链接框架目标的\Build Phases \Compile Sources阶段。

  3. 将要公开的标题放入\Build Phases \Headers。

  4. 对于动态链接框架,请记得检查Mach -O在构建设置中键入设置。如果要使用swift,则需要确保将Mach-O类型设置为动态库,以使其成为动态链接框架。对于静态链接框架,您需要将Mach-O类型设置为静态库,但不能在转换后的静态链接框架中使用swift(仅允许使用objective-c,objective-c ++,C ++,C等) 。

  1. Add a new cocoa touch framework as a TARGET in your existing static linked library project.
  2. In the Build Phases, adding all the .m, .mm, .c, .cpp, .metal, etc. into "\Build Phases\Compile Sources" phase of your static linked framework target.
  3. Put the headers that you want to exposed in to "\Build Phases\Headers".
  4. For dynamic linked framework, remember to check the Mach-O Type setting in your Build Settings. If you are going to use swift, you need to make sure the Mach-O type is set as dynamic library so that it will become a dynamic linked framework. For static linked framework, you'll need to set the Mach-O type as static library, but you cannot use swift in the converted static linked framework (only objective-c, objective-c++, C++, C, etc. are allowed).

然后对于想要使用此框架的应用程序,只需将标题包含为#import并将框架添加到Build中Phases \ Link Binary With Librariesof your App Target。如果转换的框架是动态链接框架,则需要将其放入嵌入式二进制文件。

Then for the app that wants to use this framework just need to include the headers as #import and add the framework into "Build Phases\Link Binary With Libraries" of your App Target. If the converted framework is dynamic linked framework, you will need to put it into "Embedded Binaries".

这篇关于将静态库目标转换为Xcode项目中的框架目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆