直接上結(jié)論
(結(jié)論針對本公司的工程而言,項目不同數(shù)據(jù)會有所不同):
- OC 和swift 混編會讓iPA 的包增大20M,即使你只有幾個swift 文件,每一個swift文件代碼都不多都可能增加20M
- bitcode 會讓ipa 包增加1.5M左右
- cocoapod 的設(shè)置Objc打開會增加ipa的大小,幾M左右,而且這個Objc 是最好要打開的
- 文中還使用了RAC ,RAC對ipa的大小影響還沒測試,有知道的歡迎給我留言
1) oc和swift 混編,bitcode 勾選上,ipa 文件大小49.8M
49.8M有點大 ,30M的時候老板就想更小點,50M老板估計不好接受

Snip20160809_11.png

Snip20160809_8.png
2) oc和swift 混編,bitcode 未選上,ipa 文件大小48.4M,比上面減少了1.4M

Snip20160809_9.png
3) 刪除項目中的swift 文件,改為純OC,ipa為29.7M,減少20M啊

Snip20160809_10.png
4) cocoapod中設(shè)置Objc 會讓ipa 增大
cocoapod這么好用的工具,增大ipa 還是得用的.cocoapod 會讓ipa 增大的,我沒測試,詳情見這位老外的問答.
問題:CocoasPod很好,但是-ObjC 在項目中會讓所有的對象文件編譯到二進制文件中,一個空的工程使用pod AFNetworking和"ObjC"打開,ipa的大小是7M.google map 需要ObjC 打開,這樣導(dǎo)致ipa 17M ,所以這個老外想知道, Google Map SDK 的ObjC 打開,AFNetworking 的ObjC 關(guān)閉去減少ipa 的大小?
答案:別人的答案沒說怎么辦,只是說cocoapod 這么做是為了程序更好的編譯.
CocoasPod is good, But sometimes it's not.Why? Because there is a flag call "-ObjC" in your project.It will pull ALL OBJECT FILES into your resulting binary.
For example, an empty project with "pod 'AFNetworking'" and the flag "-ObjC" is on, that will cause the binary will be 7MB. 7MB for an empty project, that's suck.
Some frameworks like Google Map SDK need the flag "-ObjC" is on.So, if your project with "AFNetworking pod" and "Google Map SDK", it will cause the binary will be 17MB.
So my question is:How can I turn off the "-ObjC" flag for special Library?For example, just keep the "-ObjC" for Google Map SDK, but turn it off on AFNetworking.
In general, adding a static library to your project in Objective-C will pull ALL OBJECT FILES into your resulting binary because cocoa pods installation adds -ObjC flag to your linker settings, and as stated in linker manual:
-ObjC Loads all members of static archive libraries that implement an Objective-C class or category.
This flag included to solve problem with linking categories, because by default linker will not include object files containing only categories into resulting binary.
文中的打包出的ipa大小都包含了RAC 和cocoapad.RAC對ipa的大小影響還沒測試,估計在7M以內(nèi),
- 最后的結(jié)論見文章開頭,有不同的意見歡迎留言
- 作者開發(fā)經(jīng)驗總結(jié)的文章推薦,持續(xù)更新學(xué)習(xí)心得筆記
Runtime 10種用法(沒有比這更全的了
成為iOS頂尖高手,你必須來這里(這里有最好的開源項目和文章)
iOS逆向Reveal查看任意app 的界面
JSPatch (實時修復(fù)App Store bug)學(xué)習(xí)(一)
iOS 高級工程師是怎么進階的(補充版20+點)
擴大按鈕(UIButton)點擊范圍(隨意方向擴展哦)
最簡單的免證書真機調(diào)試(原創(chuàng))
通過分析微信app,學(xué)學(xué)如何使用@2x,@3x圖片
TableView之MVVM與MVC之對比
使用MVVM減少控制器代碼實戰(zhàn)(減少56%)
ReactiveCocoa添加cocoapods 配置圖文教程及坑總結(jié)