开发者

Are unused classes compiled by Xcode when building an app?

If something is not used in C++, it's not compiled at all. Is the same true for iPhone? If I compile a program and there are unused classes or o开发者_C百科ther stuff, will it be compiled or ignored?


It depends on your build settings.

Under your target build settings, then under "Linking" there is an option for "Dead Code Stripping". It defaults to yes for projects created with Xcode.

Are unused classes compiled by Xcode when building an app?

Here's a link to the build settings documentation from Apple (with an excerpt):

https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html

DEAD_CODE_STRIPPING (Dead Code Stripping)

Description: Boolean value.

Specifies whether dead code is stripped from the binary.

Prerequisite: $GCC_DEBUGGING_SYMBOLS = full

Values:

YES: Dead code is stripped from the binary when the prerequisite is met.

NO: Dead code is not stripped from the binary.

Default value: NO Companions: “GCC_DEBUGGING_SYMBOLS (Level of Debug Symbols).” Prerequisite for: PRESERVE_DEAD_CODE_INITS_AND_TERMS

Note, the docs say the value defaults to NO, but Xcode project settings default the value to YES.


I believe that any resource that is added to a target will get compiled and/or copied to your application bundle at build time. To edit which files are built/copied, you can modify the settings in Xcode 4, by clicking on project, then your target. Under Build Phases, you can change the files as needed.

Here's a screenshot:

Are unused classes compiled by Xcode when building an app?

There is also a setting for Dead Code Stripping under Build Settings. Here's what that looks like:

Are unused classes compiled by Xcode when building an app?

It defaults to yes, but if you want to disable it for some reason, that's how you'd do so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜