接下來開始介紹一下在iOS開發(fā)中靜態(tài)庫的制作。提示:開源光榮 與學(xué)習(xí)靜態(tài)庫的制作沒有任何關(guān)系。將自優(yōu)秀代碼開源的同志,都是好同志。
一、創(chuàng)建項目
開始創(chuàng)建項目:

項目命名:

二、核心代碼
目的是寫一個簡單的 UITableViewCell 的子類。
進(jìn)入 BaseCell.h 文件,讓 BaseCell 繼承于 UITableViewCell 。并聲明以下兩個類方法:
/** 快速獲取 cell */
+ (instancetype)cell:(UITableView*)tableView;
/** 快速獲取 cell(Xib/故事版) */
+ (instancetype)resourceCell:(UITableView*)tableView;
在 BaseCell.m 文件中實現(xiàn)以上兩個方法:
/** 快速獲取 cell */
+ (instancetype)cell:(UITableView*)tableView {
NSString* ID = NSStringFromClass(self);
BaseCell* cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
[tableView registerClass:self forCellReuseIdentifier:ID];
cell = [tableView dequeueReusableCellWithIdentifier:ID];
}
return cell;
}
/** 快速獲取 cell(Xib/故事版) */
+ (instancetype)resourceCell:(UITableView*)tableView {
NSString* ID = NSStringFromClass(self);
BaseCell* cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
[tableView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellReuseIdentifier:ID];
cell = [tableView dequeueReusableCellWithIdentifier:ID];
}
return cell;
}
寫到這里,大家應(yīng)該都知道這個 BaseCell 的功能了。聰明的你,也知道了我的意圖。
三、打靜態(tài)包前的配置
1、Build Active Architecture Only 全部設(shè)置成NO。

2、這里是不用修改的,默認(rèn)就是這樣。

四、開始編譯
分別選中模擬器于真機(jī),各自都編譯一下:

** command + b** 編譯成功為止。

command + b 編譯成功為止。
五、找到編譯結(jié)果
找到左側(cè)的 Products 目錄。選中libBaseCell.a進(jìn)入,會發(fā)現(xiàn)有如下兩個子目錄:

兩個子目錄,就是編譯結(jié)果。分別進(jìn)入字目錄中,會發(fā)現(xiàn)有這樣的文件libBaseCell.a,這就是一個靜態(tài)庫了,但是模擬器于真機(jī)的是分開的。在開發(fā)中,往往是需要合并的。打開終端,cd 到 Products 目錄。
然后在終端合并兩個 libBaseCell.a ,語法是:
lipo -create 第一個libBaseCell.a 第二個libBaseCell.a -output libBaseCell.a (粗體為固定字段)
例如:
lipo -create /Users/zhuhong/Library/Developer/Xcode/DerivedData/BaseCell-arwrstdmbuakyafbrvinyfrhqhlp/Build/Products/Debug-iphoneos/libBaseCell.a /Users/zhuhong/Library/Developer/Xcode/DerivedData/BaseCell-arwrstdmbuakyafbrvinyfrhqhlp/Build/Products/Debug-iphonesimulator/libBaseCell.a -output libBaseCell.a
會發(fā)現(xiàn)在 Products 目錄中多了一個 libBaseCell.a 文件。這個文件就是模擬器于真機(jī)合并的靜態(tài)庫,在開發(fā)的過程中,往往都是用這個合并庫。
然后在 Products 目錄中創(chuàng)建一個目錄,名叫 BaseCell。 BaseCell目錄中內(nèi)容如下:

結(jié)束了,現(xiàn)在你將BaseCell 目錄拖到項目,就可以使用了。
想要了解更多,可以進(jìn)入iOS 靜態(tài)庫制作?中篇