Reputation: 2541
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".
Upvotes: 2
Views: 8572
Reputation:
If you select Product -> Scheme -> Edit Scheme
, then target the Run scheme, you'll see that it has two build configurations:
-O0
for no optimization.-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.
Upvotes: 7