如何将Xcode项目转换为静态库或框架? [英] How to convert an Xcode project into a static library or framework?

查看:255
本文介绍了如何将Xcode项目转换为静态库或框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,需要将其作为框架导入到其他项目中,就像我们如何导入Coredata框架,Quartzcore等.如何实现该目标?如何将我的项目编译到可以导入其他项目的库或框架中?请说明步骤.

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.

谢谢.

推荐答案

如果要编译UIKit.framework之类的标准"框架,请尝试以下

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

其他

  1. 创建一个名为"TestPlugin"的新项目,然后选择类型"Cocoa touch Static Library".在这里,您将有一个目标'TestPlugin.a'.
  2. 添加新目标.在项目设置的左上角,名称为:添加目标".在"OS X"的框架和库"中选择捆绑".这是您的第二个目标,名为"TestPluginBundle.bundle".
  3. 在TestPlugin.a目标的构建短语"设置中,添加一个新的目标密度".这将首先生成.bundle文件,然后生成.a文件.
  4. 将所有原始"项目的文件(不包括main.m和.xcodeproj文件)复制并添加到TestPlugin项目中.
  5. 在TestPluginBundle的构建阶段"设置中,将所有.xib .png(也许是.jpg)文件添加到编译源"中.将空间资源(例如.wav,.gif和.html)添加到复制捆绑资源"中.
  6. 将所有从主包加载资源的代码替换为从TestPluginBundle加载资源的代码.也许您想为UIImage添加类别,因为您想使用imageNamed:以便可以使用[UIImage testPluginImageNamed:@"small.png"].在项目中进行替换并添加相关的头文件很容易.以.xib文件为例:

  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]];
    ...
}

  • 在此之后,将.a文件和.bundle文件添加到另一个项目中.在另一个项目中,您需要再次添加相关框架.

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

    这篇关于如何将Xcode项目转换为静态库或框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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