簡體   English   中英

如何將Xcode項目轉換為靜態庫或框架?

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

我有一個項目,我需要導入到其他項目作為框架,就像我們如何導入Coredata框架,Quartzcore等...如何實現? 如何將我的項目編譯成可以導入到其他項目的庫或框架? 請解釋一下步驟。

提前致謝。

https://github.com/jverkoey/iOS-Framework嘗試使用此鏈接創建框架和資源包。將項目中使用的圖像,xib和其他資源包裝成bunble並將類復制到Cocoa觸摸靜態庫項目。

如果你想編譯像UIKit.framework這樣的“標准”框架,試試這個Universal Framework iPhone iOS

其他

  1. 創建一個名為“TestPlugin”的新項目,然后選擇“Cocoa touch Static Library”。 在這里你將有一個目標'TestPlugin.a'。
  2. 添加新目標。 在項目設置的左下角,名稱為:“添加目標”。 在“OS X”中的“框架和庫”中選擇“捆綁”。 這是你的第二個目標名為'TestPluginBundle.bundle'。
  3. 在TestPlugin.a目標的“Build Phrases”設置中,添加一個新的“Target Denpendencies”。 這將首先生成.bundle文件,然后生成.a文件。
  4. 將所有“原始”項目的文件(不包括main.m和.xcodeproj文件)復制並添加到TestPlugin項目中。
  5. 在TestPluginBundle的“Build Phases”設置中,將所有.xib .png(可能是.jpg)文件添加到“Compile Sources”。 將空間資源(例如.wav,.gif和.html)添加到“復制捆綁資源”。
  6. 替換從主bundle加載資源的所有代碼,以從TestPluginBundle加載資源。 也許你想為UIImage添加一個類別因為你想使用imageNamed:所以你可以使用[UIImage testPluginImageNamed:@"small.png"] 在項目中替換很容易並添加相關的頭文件。 以.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. 之后,將.a文件和.bundle文件添加到另一個項目中。 在另一個項目中,您需要再次添加相關框架。

我已經成功地將這種方法用於我的工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM