如何减少iPhone应用程序的代码大小?
我的 iPhone 应用程序正准备投入生产,我们希望塞入尽可能多的数据。当我浏览为我的应用程序生成的 .app 文件时,我看到一个名为
My iPhone app is getting ready to go to production and we like to cram in as much data as possible. When I poke around the generated .app file for my application I see a file named <executable name> which I assume is the compiled code. It is about 2.5 megs which seem large for what I am including in my app. What type of things should I check to make sure there aren't any unneeded items being included into my executable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做很多事情——2.5 MB 是一个小应用程序。
一个明显的方法是验证您的二进制文件实际上已被删除。这会删除未使用的引用(例如未实际调用的函数)和调试信息。
链接时间优化 (LTO) 可以为您节省大量空间,尽管这适用于程序的 C 和 C++ 方面。它使我的一个程序的大小缩小到大约 1/5。
使用优化设置。
O3
和O2
通常会生成比Os
更小的二进制文件。跟踪您的依赖库。它们导出的符号可能相对较大。
在大型项目中优先使用 C 或 C++ 来共享库。如果未使用,它们可能会被剥离或优化。
最小化
static
数据和static
函数,将其范围限制为 c、cpp、m、mm 文件。There are a number of things you could do -- 2.5 MB is a small app.
One obvious way is to verify that your binary is in fact stripped. This removes unused references (e.g. functions which are not actually called) and debugging info.
Link Time Optimization (LTO) can save you a ton of space, although that applies to the C and C++ aspects of your program. It brought one of my programs down to about 1/5 the size.
Play with optimization settings.
O3
andO2
often produce a smaller binary thanOs
.Keep track of your dependent libraries. Their exported symbols may be relatively large.
Favor C or C++ for shared libraries in larger projects. If unused, they may be stripped or optimized away.
Minimize
static
data andstatic
functions, restricting their scope to the c, cpp, m, mm file.我可能不会过分担心该应用程序有 2.5MB,但如果您想进行尽职调查以确保只包含真正需要的内容,我会查看所有资源文件(图像、视图、电影等),并确保应用程序正在使用它们。
I probably wouldn't be overly concerned about the app being 2.5MB, but if you want to do due diligence in making sure you're only including what is really needed, I'd take a look at all of the resource files (images, views, movies, etc) that your project references and make sure that all of them are being used by the application.