iOS Swift Newbie Gotcha Reminders #6 — Speed bumps & How to optimize XCode 10 for faster Build Times!!!!

Raymond
iOS Newbies
Published in
4 min readMar 3, 2019

--

This is a series of of multiple XCode / Swift / iOS Programming Gotchas to remind myself and hopefully relieve the stresses of many other beginner programmers whom are struggling with developing iOS apps via XCode.

Learning is a process of making many mistakes.

6. Speedup XCode Build Time!!!

Step 1. Turn on Build time

Type the follow in terminal / command line to enable build time information to be displayed onto your Xcode build status.

defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
You will see build time next to the status

Tip: It’s probably a good idea to remove your derived data too before to help you test build times if you want to benchmark build times with further optimizations.

rm -rf ~/Library/Developer/Xcode/DerivedData

Step 2. Correctly set optimization levels

Notice1 : Compilation Mode: for debug should always be Incremental and release should be Whole Module

Notice2: Optimization Level: by default should be set correctly when you start a new project.

You may read more about swift optimization through the link below:

Alternatively, if you use cocoapods you may probably edit your pod’s post install method to enable the correct options without having to fiddle with each setting.

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == 'Debug'
config.build_settings['OTHER_SWIFT_FLAGS'] = ['$(inherited)', '-Onone']
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule'
end
end
end
end

Step 3. Reduce concurrent number of jobs and get the right hardware for the right job.

https://www.linkedin.com/pulse/best-hardware-build-swift-what-you-might-think-jacek-suliga/

The law of diminishing returns is in act here. You will see that having more concurrent jobs to match the number of cpu’s will drastically slow down build times.

It’s recommended that if you have more than 4 cores in your machine to reduce it down to 5 concurrent jobs.

Through terminal command line enter the following to set the maximum number of concurrent jobs allowed for Xcode with the following command.

defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 5

Step 4. Ensure“parallelize build” setting in XCode10

Go to your schemes:

Edit Schemes > Build > Build Options and make sure the parallelize build is turned on.

In XCode9 the resources are build in a linear fashion which took more time to build. However in XCode10, we can take advantage of parallelize build settings to drastically improve our build times by all our resources in parallel.

References:

Cheers!

while(button.mouseDown) {clapCounter++}

--

--