简体   繁体   English

如何将Xcode项目转换为静态库或框架?

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

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 ? 我有一个项目,我需要导入到其他项目作为框架,就像我们如何导入Coredata框架,Quartzcore等...如何实现? How to compile my project into a library or framework which can be imported into other projects ? 如何将我的项目编译成可以导入到其他项目的库或框架? Please explain the steps. 请解释一下步骤。

Thanks in advance. 提前致谢。

https://github.com/jverkoey/iOS-Framework尝试使用此链接创建框架和资源包。将项目中使用的图像,xib和其他资源包装成bunble并将类复制到Cocoa触摸静态库项目。

If you want to compile a 'standard' framework like UIKit.framework, try this Universal Framework iPhone iOS 如果你想编译像UIKit.framework这样的“标准”框架,试试这个Universal Framework iPhone iOS

else 其他

  1. Create a new Project named 'TestPlugin' and choose type "Cocoa touch Static Library". 创建一个名为“TestPlugin”的新项目,然后选择“Cocoa touch Static Library”。 Here you will have a target 'TestPlugin.a'. 在这里你将有一个目标'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'. 在“OS X”中的“框架和库”中选择“捆绑”。 This your second target named 'TestPluginBundle.bundle'. 这是你的第二个目标名为'TestPluginBundle.bundle'。
  3. In your TestPlugin.a target's 'Build Phrases' setting, add a new 'Target Denpendencies'. 在TestPlugin.a目标的“Build Phrases”设置中,添加一个新的“Target Denpendencies”。 This will firstly generate the .bundle file and then the .a file. 这将首先生成.bundle文件,然后生成.a文件。
  4. Copy and add all your 'Original' project's file(exclude the main.m and the .xcodeproj file) to TestPlugin project. 将所有“原始”项目的文件(不包括main.m和.xcodeproj文件)复制并添加到TestPlugin项目中。
  5. In TestPluginBundle's 'Build Phases' setting, add all .xib .png(maybe .jpg) file to 'Compile Sources'. 在TestPluginBundle的“Build Phases”设置中,将所有.xib .png(可能是.jpg)文件添加到“Compile Sources”。 Add spacial resource(such as .wav, .gif and .html) to 'Copy Bundle Resources'. 将空间资源(例如.wav,.gif和.html)添加到“复制捆绑资源”。
  6. Replace all code that load resource from main bundle to load resource from TestPluginBundle. 替换从主bundle加载资源的所有代码,以从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"] . 也许你想为UIImage添加一个类别因为你想使用imageNamed:所以你可以使用[UIImage testPluginImageNamed:@"small.png"] It's easy to do replace in your project and add the related header file. 在项目中替换很容易并添加相关的头文件。 Take .xib file For example: 以.xib文件为例:

     - (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. 之后,将.a文件和.bundle文件添加到另一个项目中。 In the another project you need to add the related framework again. 在另一个项目中,您需要再次添加相关框架。

I've successfully used this method for my work. 我已经成功地将这种方法用于我的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM