简体   繁体   English

将iOS应用编译为静态库

[英]iOS app compiled as static library

I'm about to customize a project for several clients. 我将为几个客户定制一个项目。 The project uses CocoaPods and Storyboard. 该项目使用CocoaPods和Storyboard。 Since i'm expecting to fix some bugs and make some changes in the UI for each client along the way, I want to organize the projects like so: 1. Turn the starting iOS app into a compiled Static Library (somehow) 2. Create the new customized app. 由于我期望在此过程中为每个客户端修复一些bug并在UI中进行一些更改,因此我想像这样组织项目:1.将启动的iOS应用程序转换为已编译的静态库(以某种方式)2.创建新的定制应用程序。 Link it to the Static Library. 将其链接到静态库。 3. Copy the original Storyboard into the new customized App. 3.将原始的情节提要板复制到新的自定义应用程序中。

Now in the "new" storyboard I can apply changes according to the client needs. 现在,在“新”情节提要中,我可以根据客户需求应用更改。 Every ViewController in the Storyboard references as Custom Class has a class defined in the original app (now the compiled static library). 故事板中作为“自定义类”引用的每个ViewController都有一个在原始应用程序(现为已编译的静态库)中定义的类。 This way I can always replace or extend original classes and set the new one to be the Custom Class of my ViewControllers in the storyboard. 这样,我就可以始终替换或扩展原始类,并在情节提要中将新类设置为ViewController的自定义类。

It sounds good to me. 对我来说听起来不错。 But I can't get it working. 但是我无法正常工作。 1. I managed to create a static library out of the original iOS app adding a secondary target to the project as Static Library. 1.我设法从原始的iOS应用程序中创建了一个静态库,为该项目添加了一个辅助目标作为“静态库”。 After struggling with headers search path, flags and linking frameworks I got it compiled (with LOT'S of warnings) 2. I created a new Project and linked the static library but can't get it compiled. 经过标题搜索路径,标志和链接框架的苦苦挣扎后,我对其进行了编译(带有很多警告)。2。我创建了一个新的Project并链接了静态库,但无法对其进行编译。

My Question is. 我的问题是。 1. Am I doing this the right way? 1.我这样做正确吗? 2. If I have a static library with related header files and I create another static library that uses the previous. 2.如果我有一个带有相关头文件的静态库,并且我创建了另一个使用前一个的静态库。 If I want to use the second created library into a new project, do I have to link it against both libraries and header files? 如果要将第二个创建的库用于新项目,是否必须将其链接到库和头文件?

  1. It should work in theory, although I personally would have gone the route of creating a static Framework instead of a static library, since the framework should be easier to link to, can have different versions for different architectures, and includes the header in the same package. 它应该在理论上起作用,尽管我个人本来会创建静态框架而不是静态库,因为该框架应该更易于链接,对于不同的体系结构可以有不同的版本,并且在同一框架中包含标头包。 Check out this project for adding a Framework project type to Xcode: https://github.com/kstenerud/iOS-Universal-Framework . 签出此项目以向Xcode添加Framework项目类型: https : //github.com/kstenerud/iOS-Universal-Framework (Someone REALLY needs to get on Apple to include the Framework target type by default) (默认情况下,确实需要有人在Apple上加入Framework目标类型)

  2. Someone can correct me if I am wrong, but as far as I understand things: Yes, you will need to link both libraries into the final executable. 如果我错了,有人可以纠正我,但据我了解::是的,您需要将两个库都链接到最终的可执行文件中。 Compiling library 2 against library 1 does NOT combine library 1's code into library 2. 针对库1编译库2不会将库1的代码合并到库2中。

We would need to get more specific info on the compilation errors to help you link the static library into your new project. 我们将需要获取有关编译错误的更多具体信息,以帮助您将静态库链接到新项目中。

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

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