How to convert an Xcode project into a static library or framework?

坚强是说给别人听的谎言 提交于 2020-07-17 05:35:45

问题


I have a project which I need to import into other project as a framework just like how we import Coredata framework, Quartzcore etc..How to achieve that ? How to compile my project into a library or framework which can be imported into other projects ? Please explain the steps.

Thanks in advance.


回答1:


https://github.com/jverkoey/iOS-Framework try this link for creation of framework and bundle of resources.wrap up the images, xibs and other resources you have used in your project into a bunble and copy your classes to your Cocoa Touch Static Library project.




回答2:


If you want to compile a 'standard' framework like UIKit.framework, try this Universal Framework iPhone iOS

else

  1. Create a new Project named 'TestPlugin' and choose type "Cocoa touch Static Library". Here you will have a target 'TestPlugin.a'.
  2. Add a new target. In left corner of project's setting, the name is:'Add Target'. Choose 'Bundle' in 'Framework and Library' in 'OS X'. This your second target named 'TestPluginBundle.bundle'.
  3. In your TestPlugin.a target's 'Build Phrases' setting, add a new 'Target Denpendencies'. This will firstly generate the .bundle file and then the .a file.
  4. Copy and add all your 'Original' project's file(exclude the main.m and the .xcodeproj file) to TestPlugin project.
  5. In TestPluginBundle's 'Build Phases' setting, add all .xib .png(maybe .jpg) file to 'Compile Sources'. Add spacial resource(such as .wav, .gif and .html) to 'Copy Bundle Resources'.
  6. Replace all code that load resource from main bundle to load resource from TestPluginBundle. Maybe you want to add a category for UIImage because you want to use imageNamed: so that you can use [UIImage testPluginImageNamed:@"small.png"]. It's easy to do replace in your project and add the related header file. Take .xib file For example:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        //self = [super initWithNibName:nibNameOrNil bundle:[NSBundle mainBundle]];
        // you need to define a method to get the bundle 'TestPluginBundle.bundle', here I used '[TestPlugin TestPluginBundle]'
        self = [super initWithNibName:nibNameOrNil bundle:[TestPlugin TestPluginBundle]];
        ...
    }
    
  7. After this add the .a file and .bundle file to another project. In the another project you need to add the related framework again.

I've successfully used this method for my work.



来源:https://stackoverflow.com/questions/13191193/how-to-convert-an-xcode-project-into-a-static-library-or-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!