图书馆?静止的?动态的?还是框架?另一个项目中的项目 [英] Library? Static? Dynamic? Or Framework? Project inside another project

查看:24
本文介绍了图书馆?静止的?动态的?还是框架?另一个项目中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的 iOS 应用程序,并想添加一大块我一直在开发的代码作为另一个项目,只是为了便于测试.新块主要处理将图像保存到各种共享服务等.因为共享代码需要大量测试和未来更新,我想知道将代码块合并到我现有应用程序的最佳方法是什么.

I have an existing iOS app and want to add a large chunk of code that I've been developing as another project just for ease of testing. The new chunk basically deals with saving an image to various sharing services, etc.. Because that sharing code needs a lot of testing and future updating, I was wondering what the best way to incorporate that code chunk into my existing app.

我不知道它应该是静态库、动态库还是框架,老实说,我不太确定有什么区别,或者我应该如何着手并在 Xcode 中设置它.

I don't know if it should be a static library, dynamic library or a framework, and honestly, I'm not really sure what the difference is, or how I should go about it and get it set up in Xcode.

我所知道的是,我需要/想要为共享代码保留一个单独的测试和更新应用程序,并让主应用程序使用它.

All I know is that I need/want to keep a separate testing and updating app for the sharing code and have the main app use it.

推荐答案

首先,一些通用的定义(特定于iOS):

First, some general definitions (specific to iOS):

静态库 - 在编译时链接的代码单元,不会改变.

Static library - a unit of code linked at compile time, which does not change.

但是,iOS 静态库不允许包含图像/资产(仅限代码).不过,您可以使用媒体包来解决这一难题.

However, iOS static libraries are not allowed to contain images/assets (only code). You can get around this challenge by using a media bundle though.

可以在维基百科这里上找到更好、更正式的定义.

A better, more formal definition can be found on Wikipedia here.

动态库 - 在运行时链接的代码和/或资产单元,<​​em>可能发生变化.

Dynamic library - a unit of code and/or assets linked at runtime that may change.

但是,只有 Apple 可以为 iOS 创建动态库.您不能创建这些,因为这会导致您的应用程序被拒绝.(参见这个其他所以发帖以供确认和推理).

However, only Apple is allowed to create dynamic libraries for iOS . You're not allowed to create these, as this will get your app rejected. (See this other SO post for confirmation and reasoning on such).

软件框架 - 一组完成任务的已编译代码...因此,您实际上可以拥有静态框架动态框架,通常只是上述内容的编译版本.

Software Framework - a compiled set of code that accomplishes a task... hence, you can actually have a static framework or a dynamic framework, which are typically just the compiled versions of the above.

有关详细信息,请参阅软件框架维基.

See the Wiki on Software Framework for more details.

因此在 iOS 上,您唯一的选择基本上是使用静态库或静态框架(主要区别在于静态框架最常作为编译的 .a 文件分发,而静态框架通常作为编译的 .a 文件分发)库可以简单地作为子项目包含 - 您可以看到所有代码 - 首先编译,其结果 .a 文件用作项目的依赖项).

Hence on iOS, your only option is basically to use a static library or static framework (the main difference being that a static framework is distributed as a compiled .a file most often, whereas a static library may simply be included as a subproject - you can see all of the code - which is compiled first and its resulting .a file used as a dependency by the project).

既然我们已经清楚(呃)这些条款,为 iOS 设置一个静态库和支持媒体包并不是太困难,并且有很多关于如何做到这一点的教程.我个人会推荐这个:

Now that we're clear(er) on these terms, setting up a static library and supporting media bundle for iOS isn't too difficult, and there are many tutorials on how to do such. I personally would recommend this one:

https://github.com/jverkoey/iOS-Framework

这是一个非常直接的指南,没有处理假静态库"的缺点......查看更多信息......

This is a pretty straight-forward guide and doesn't have the disadvantage of dealing with "fake static libraries"... check it out for more info...

创建静态库后,就像将其作为子模块包含在 Git 中以供不同项目使用一样简单.

Once you've created your static library, it's as easy as including it as a submodule within Git for use across different projects.

祝你好运.

编辑

关于项目中的子项目,据我所知,要使其正常工作/编译,您基本上必须设置一个编译链,其中首先编译子项目,从而创建项目用作依赖项的静态框架 .a 文件.

Regarding a subproject within a project, as far as I know, to get this to work/compile correctly, you essentially have to set up a compile chain where the subproject is compiled first, which creates a static framework .a file that is used as a dependency by the project.

这是另一个讨论此问题的有用教程:

Here's another useful tutorial which talks about this:

http://www.cocoanetics.com/2011/12/sub-projects-in-xcode/

编辑 2

从 iOS 8 开始,Apple 现在允许开发人员创建动态框架!(注意:您的应用必须至少针对 iOS 8 才能包含动态框架……不允许向后移植.)

As of iOS 8, Apple now permits developers to create dynamic frameworks! (Note: your app must have a minimum target of iOS 8 to include a dynamic framework... back porting isn't allowed.)

这已被添加为新的项目模板.在 Xcode 6.1 中,可以在以下位置找到:

This has been added as a new project template. In Xcode 6.1, this can be found at:

New Project -> iOS -> Framework & Library -> Cocoa Touch Framework

这篇关于图书馆?静止的?动态的?还是框架?另一个项目中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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