一楞艾、Swift 默認(rèn)打Daynamic Framework参咙。
無需另外創(chuàng)建Bundle文件,直接和主工程一樣創(chuàng)建storyboard和Assets文件夾硫眯。
正確資源獲取
storyboard:
let bundle = Bundle(for: Self.self)
let storyboard = UIStoryboard(name: "AFStoryboard", bundle: bundle)
let vc = storyboard.instantiateViewController(withIdentifier: "AFViewController")
獲取Assets文件夾中的image:
let bundle = Bundle(for: Self.self)
let image = UIImage(named: "imageName", in: bundle, compatibleWith: nil)
手動(dòng)引入framework蕴侧,然后主工程要在
Targets -> General -> Frameworks, Libraries, and Embedded Content
將 Embed 設(shè)置為:
Embed & Sign 或者 Embed Without Signing,
簽名與否看具體情況两入。只有簽名相同的Daynamic Framework才能和主工程共享資源净宵。
二、framework依賴關(guān)系
有Main、A择葡、B 三個(gè)工程紧武。Main為主工程,A敏储、B都是framework阻星。
Main依賴A,A又依賴B已添。
1妥箕、如果A和B是在同一個(gè)workspace,A只對B添加了依賴更舞,并沒有將B手動(dòng)拖到A的項(xiàng)目創(chuàng)建內(nèi)部的frameworks包含的時(shí)候畦幢。AFramework中是沒有BFramework文件的,只是在連接的時(shí)候會(huì)去尋找BFramework缆蝉。這時(shí)候宇葱,Main工程就要集成BFramework才能正常運(yùn)行。這也是正常A外部依賴打包操作刊头。
pod依賴管理就是這樣黍瞧。A如果使用了pod管理,在pod創(chuàng)建的workspace中芽偏,A其實(shí)只是在Build Phases中Link Binary With Libraries 將 pod工程中的framework標(biāo)記進(jìn)來而已雷逆。并沒有將這些依賴的framework拷貝到自己內(nèi)部。
2污尉、如果A是將B作為內(nèi)部的frameworks手動(dòng)拖進(jìn)來膀哲,形成內(nèi)部frameworks包含依賴的一部分的話。這時(shí)候B就是AFramework整體的一部分被碗。Main就只需要引入A即可某宪,鏈接過程中,Main能在A內(nèi)部順利的找到B锐朴。
3兴喂、其實(shí)如果這時(shí)候強(qiáng)行將A內(nèi)部的B拖出來,再在Main中將B引入焚志,效果是一樣的衣迷。所以將B拖到A里,只是手動(dòng)的改變了它所依賴的文件的存放位置而已酱酬。
4壶谒、如果A里已經(jīng)包含有B,這時(shí)候再從主工程拖一個(gè)BFramework進(jìn)來膳沽,這時(shí)候運(yùn)行汗菜,只會(huì)運(yùn)行主工程拖進(jìn)來的BFramework让禀。應(yīng)該內(nèi)部搜索依賴的路徑時(shí),時(shí)先從主工程目錄開始陨界,找到后就不再繼續(xù)搜這個(gè)依賴了巡揍。
三、使用了pod 管理引入framework
四菌瘪、使用了pod 直接源碼管理
五腮敌、有和OC混編的情況
六、打包腳本
Sets the target folders and the final framework product.
FMK_NAME=${PROJECT_NAME}
Install dir will be the final output to the framework.
The following line create it in the root folder of the current project.
INSTALL_DIR={FMK_NAME}.framework
Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR={FMK_NAME}.framework
SIMULATOR_DIR={FMK_NAME}.framework
Building both architectures.
xcodebuild -configuration "Release" -target "{FMK_NAME}" -sdk iphonesimulator
Cleaning the oldest.
if [ -d "{INSTALL_DIR}"
fi
Creates and renews the final product folder.
mkdir -p "${INSTALL_DIR}"
Copies the headers and resources files to the final product folder.
cp -R "{INSTALL_DIR}/"
Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "{FMK_NAME}" "{FMK_NAME}" -output "{FMK_NAME}"
rm -r "{PROJECT_DIR}/Products"