分為兩大步:
? ? ? ? ? ? ?一, 自定義 Framework
? ? ? ? ? ? ?二,使用Framework
一, 自定義 Framework
1,創(chuàng)建自定義framework 工程


2,創(chuàng)建自定義 framework 的類,相信大家都會了.但是還貼圖.


3,將創(chuàng)建的類引入到以工程名命名的頭文件中

4,配置 framework, 將要暴露的頭文件配置好,很簡單.

到此為止,直接編譯得到的 framework 就是可用的,但是是有局限的,只能是在模擬器上的,真機直接就 GG了 ,恐怕為了 get 這個技能不只是為了ZB,所以為了真正的技術(shù),還是要繼續(xù)往下刨.comeon~~ follow me!
5,在原來的工程中,創(chuàng)建新的target, 名字按自己心情取.

然后添加 shell 執(zhí)行腳本



shell 腳本如下:
# Sets the target folders and the final framework product.
# 如果工程名稱和Framework的Target名稱不一樣的話,要自定義FMKNAME
# 例如: FMK_NAME = "MyFramework"
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=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${INSTALL_DIR}"
6,選擇剛剛創(chuàng)建的 target,command+B/R 編譯,直接彈出生成的framework ,就是它,萬能的 fw.


主要產(chǎn)物
二,使用Framework
1,創(chuàng)建一般的工程,名字無所謂,引入上面生成的 framework

重中之重來了,這個必須要添加的(特大號的字),直接上圖


不然就是這樣的結(jié)果:
Reason: image not found

以上完成后,就是調(diào)用了 ,so easy

結(jié)語:
是不是很簡單,上手體驗吧,get 新技能的必殺技,有了這個就可以讓你的工程很簡單,也可以發(fā)自己的framework 讓別人用,高大上,有木有啊!!!哈哈
=============
作者:IMSong007
鏈接:http://www.itdecent.cn/p/e807fdf229f8
來源:簡書
簡書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請聯(lián)系作者獲得授權(quán)并注明出處。