您的位置:首页 > 移动开发 > IOS开发

Static Dynamic Library Or Framework

2013-12-05 12:05 495 查看
First, some general definitions (specific to iOS):

Static library 

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

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.

Dynamic library

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

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.

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 a dependency by the project).

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...

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

Regarding a subproject within a project, as far as I know, in order to get this to work/compile correctly, you essentially have to setup 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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios cocoa