anijam
anijam

Reputation: 351

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 other stuff, will it be compiled or ignored?

Upvotes: 4

Views: 3693

Answers (2)

Steve
Steve

Reputation: 31652

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.

enter image description here

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.

Upvotes: 11

Moshe
Moshe

Reputation: 58097

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:

enter image description here

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

enter image description here

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

Upvotes: 6

Related Questions