简体   繁体   English

iOS-静态库与在多个其他项目中包含一个项目

[英]iOS — static library vs. including one project in multiple other projects

I have a bunch of code I am using in multiple projects. 我有很多在多个项目中使用的代码。 Right now, I am doing it by copy-and-paste, which is less than ideal. 现在,我正在通过复制粘贴来完成此操作,这并不理想。 As I understand it, to have multiple projects refer to the same source code, I have at least two options: 据我了解,要让多个项目引用相同的源代码,我至少有两个选择:

1) Create a static library and include it in multiple projects 1)创建一个静态库并将其包含在多个项目中

2) Create a project with the shared source code, and import that into all of the other projects. 2)使用共享的源代码创建一个项目,并将其导入到所有其他项目中。

What are the advantages and disadvantages of these approaches? 这些方法的优点和缺点是什么? When might I prefer one over the other? 我什么时候比另一个更喜欢?

您可以将项目包含在静态库中,该库将利用静态库和所包含项目的所有优点:)它运行良好,不能说这种方法的明显缺点。

The only disadvantage of including a static external librairy to your project would be the size of it; 在项目中包括静态外部库的唯一缺点是它的大小。 if you are using a library that will be "universal" (working on the simulator + the device), you'll have to target i386 and arm (today armv7). 如果使用的库是“通用的”(在模拟器和设备上运行),则必须针对i386和arm(今天为armv7)。 So you will inflate your project with "dead code" that can't be used on for your mobile solution. 因此,您将使用无法在您的移动解决方案上使用的“无效代码”为您的项目增色。

If you include a project with share source code, you'll be able to compile just what you need for you mobile device, but everybody can see your code ... 如果您包含一个包含共享源代码的项目,则可以只编译移动设备所需的内容,但是每个人都可以看到您的代码...

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

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