Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I turn on optimization in Xcode?

I have some Swift code in Xcode 7.2 that runs well, but when I run swift -O main.swift from a command line to run an optimized build of it, my code runs really fast.

How do I turn on code optimization in Xcode? I've tried Product -> Build For -> Running, but that isn't running it at optimized speed. I don't see anything in the project settings for "enable optimization" or "make a release build".

like image 990
Brian Kendig Avatar asked Jul 05 '26 18:07

Brian Kendig


1 Answers

If you select Product -> Scheme -> Edit Scheme, then target the Run scheme, you'll see that it has two build configurations:

  • Debug: Builds with option -O0 for no optimization.
  • Release: Builds with option -Os for fastest/smallest optimization.

You can find those values in the project's Build Settings, under Apple LLVM 7.0 - Code Generation, Optimization Level.

One option is to edit the Run scheme's build configuration, which defaults to Debug, and change it to Release.

Another option is to build for profiling which defaults to Release, and will build an optimized version that can be profiled.