Library? Static? Dynamic? Or Framework? Project inside another project

后端 未结 3 1844
一生所求
一生所求 2020-11-22 10:13

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 s

3条回答
  •  囚心锁ツ
    2020-11-22 10:45

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

    Good Luck.

    EDIT

    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/

    EDIT 2

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

    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
    

提交回复
热议问题