swiftxcodesampleobservation

What does Apple mean by "Enable Dead Code Stripping"


[Edit] I am not sure why I got a minus vote on this. I looked online but did not find much about what this setting does and now I got a great explanation below by Rob Napier, so I am quite happy. And I believe this can help other people too!

I found this warning in a sample app provided by Apple "Monitoring data changes in your app".

What does this mean in this context?
Also not sure what it will be stripped since it is a fairly recent code. Also the app is very small, just to demonstrate some Swift APIs.

The app can be freely download here

enter image description here


Solution

  • "Dead code" refers to compiled code that is never used in the final, linked binary. As an optimization, the linker can remove this from the binary. This is generally preferred, since it can dramatically shrink the size of the binary.

    If you statically link a library, it is very common to have large amounts of dead code, since you generally only use a small portion of the library, but all of it is initially included in your binary.

    It is occasionally useful to disable dead-code stripping. It does add time to the build process, and for debug builds it can be faster to skip it. Generally this isn't a good idea for iOS apps since you have to transfer them in order to run them, so a huge binary can be a problem. But for programs that are run directly from their build location, it can sometimes be a benefit.

    And of course if your binary does anything tricky with itself, for obfuscation purposes or for changing code at runtime, dead code stripping can occasionally break those tricks. Generally you shouldn't do that....