xcode 使用静态库打包 Bundle

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/805378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:33:17  来源:igfitidea点击:

Packaging a Bundle with a static library

iphonecocoa-touchxcodexibxcodebuild

提问by 4thSpace

I have a static library that includes some xibs. These will basically be the same across projects. I'd like to include the xibs as part of the library. I can include their veiwcontrollers, reference these controllers in the calling project but then there isn't a xib to load. When I right click the xib in the library project, it can't be part of the target.

我有一个包含一些 xib 的静态库。这些在项目中基本上是相同的。我想将 xib 作为库的一部分。我可以包含他们的 veiwcontrollers,在调用项目中引用这些控制器,但是没有要加载的 xib。当我右键单击库项目中的 xib 时,它不能成为目标的一部分。

I thought about creating a CFPluginBundle but that creates a new project. I'd loose all of my IBOutlet and IBAction references. What is the best way to reuse xibs that also have outlets and actions to specific controllers?

我想过创建一个 CFPluginBundle 但这会创建一个新项目。我会丢失我所有的 IBOutlet 和 IBAction 引用。重用对特定控制器也有出口和动作的 xib 的最佳方法是什么?

采纳答案by Ricardo Valeriano

回答by Ronen Morecki

I had the same problem when I wanted to export my project as a library for other developers to use. I found the perfect solution to my view and it seems it will answer yours too.

当我想将我的项目导出为其他开发人员使用的库时,我遇到了同样的问题。我找到了我的观点的完美解决方案,它似乎也能回答你的问题。

There is an xcode plugin that allows you to build your project as a library which includes the resources as well.

有一个 xcode 插件允许您将项目构建为包含资源的库。

https://github.com/kstenerud/iOS-Universal-Framework

https://github.com/kstenerud/iOS-Universal-Framework

I do not know the guys that built this plugin, but it works like a charm

我不认识构建这个插件的人,但它的作用就像一个魅力

回答by smorgan

I'm not sure what you mean by "include the xibs as part of the library", since static libraries can't have resources--but they also aren't shipped stand-alone, so they don't need to. If you just want code re-use for your own projects, you could keep the xibs where-ever you keep the static library, and just include the xibs in any project that uses the library.

我不确定您所说的“将 xib 作为库的一部分包含在内”是什么意思,因为静态库不能拥有资源——但它们也不是独立交付的,因此它们不需要。如果您只想为您自己的项目重用代码,您可以将 xib 保留在您保留静态库的任何位置,并且只需将 xib 包含在使用该库的任何项目中。

If you go the CFPluginBundle route, you can make new bundle targets in an existing project; there's nothing magic about the templates, they just take care of making dummy files and turning on the right build settings. You can copy those into a new target in your existing project and it will work just fine. That said, I'm not sure what you mean about losing IBOutlet and IBAction references, since that information is part of the xib (and the class you are using in the xib), not the project.

如果你走 CFPluginBundle 路线,你可以在现有项目中创建新的捆绑目标;模板没有什么神奇之处,它们只是负责制作虚拟文件并打开正确的构建设置。您可以将它们复制到现有项目中的新目标中,它会正常工作。也就是说,我不确定丢失 IBOutlet 和 IBAction 引用是什么意思,因为该信息是 xib(以及您在 xib 中使用的类)的一部分,而不是项目的一部分。