Nothing is perfect Swift has become one of the greatest modern languages, but as everything else, it has its own issues. When working on large-scale projects, you can notice an issue where Swift compile time is growing. And it's a real frustration and waste of time. I have witnessed compile times up to 5–6 mins, but there are examples that show it can grow a lot more than that. In those moments, reminds me of Android Studio in the earlier days. 🐢🐢🐢🐢 programming Xcode Wasting an hour or two daily in Swift compile time is a lot of unproductive time. That's why we must Xcode and the way we code. I will show some of the things that decreased the Swift compile time dramatically, so you can try it out and tell me if they have helped you. optimize It's optimization time! An Awesome Tool Let's start by installing this awesome open source tool, called . Install this tool by following the instructions provided on the GitHub link, and then run your project. It will analyze your code, and tell you which parts of your code take the most time to compile. It will be much easier to optimize the code with this tool, so don't skip this step. Build Time Analyzer for Xcode in action Build Time Analyzer for Xcode Xcode improvements Before going to the code, let's check some optimization tips that we can try on the IDE. — navigate to Build Settings -> Optimization Level and make sure that Debug is set to Next, go to Build Settings -> User-Defined and add . From my experience, this flag always tackles a big part of the compiling time. Tweak the Optimization Level None. SWIFT_WHOLE_MODULE_OPTIMIZATION = YES Optimization Level in Build Settings dSYM(debug symbols file) is a file which takes debugging information and stores it in a dSYM Bundle. This file is generated each time you compile your project. However, you don't need this in Debug so change the value to DWARF, and leave it active only for the Release mode. You can locate Debug Information Format setting under Build Settings. Remove dSYM file from Debug— Remove dSYM file from Debug — for all the non-release builds set Build Active Architecture Only to . This will prevent Xcode to compile files twice. You can locate Build Active Architecture Only setting under Build Settings. Check your Build Active Architecture Only values YES Check your Build Active Architecture Only values — if you have any kind of problems with building the project, you should start from here. Go to File -> Project Settings and click the arrow next to the Derived Data path. The arrow will locate the folder and just hit delete on it. Don't worry, it will recreate next time you run the project. Also, don't forget to clean the project after deleting the data (CMD+Shift+K). Empty your Derived Data Empty your Derived Data These are the Xcode improvements that give best results in decreasing the Swift compile time. Now, let's see some coding practices that you need to avoid/improve in order to get a better compile time. Recommended for you: 6 Tips For A Software Development Success Philosophy Swift improvements — you should always add type annotations to your variables. That way the compiler will already know the type of the variable, and will save time reading it. For the example, I will use array literals. Add type annotations This: let array: [String] = ["a", "b", "c", "d", "e", "f", "g"] Instead of: let array = ["a", "b", "c", "d", "e", "f", "g"] — another big improvement in compile time was noticed upon removing nil-coalescing operators. For example, working with an optional String. Avoid Nil-Coalescing operator if let name = string{/* string has value */}else{/* string is nil*/} Instead of: let name = string ?? "" ternary conditional operators are also increasing the Swift compile time. I love using both the ternary and nil-coalescing operators, as they make my code shorter and cleaner. But, we have to keep avoiding them as much as we can and work with the if-else conditionals instead. Avoid Ternary Conditional Operators — var letter = ""if isFirst{letter = "a"}else{letter = "b"} Instead of: let letter = isFirst ? "a" : "b" — Swift prefers string interpolation rather than using the "+" symbol. Believe it or not, this have saved me a lot of compile time while optimizing. Don't use + to concatenate a string This: let url = "https://google.com/\("path")/\("anotherpath")" Instead of: let url = "https://google.com/" + "path/" + "anotherpath" Never do computations directly from the if-else conditions. It takes a LOT of time to finish, and also it doesn't knows it's type yet. Only this step adds 5+ seconds to the compile time. What you need to do is, create a variable together with the type annotation that we have mentioned above, and add the calculation. After that, pass the value to the if-else condition and do your comparison. Pre-Compute — let number: Double = 60 * 60 if number == 3600{ } Instead of: if number == 60 * 60 {} Conclusion The Swift improvements might look to you as minor improvements, and you might not be sure that it can help for decreasing your compile time. But, if you can count a number of variables you declare without a type annotation or overusing of ternary/nil-coalescing operators you will get to a big number of variables and each carrying a different amount of delay. When you sum all the delays you will understand that your compile time is in xx minutes. I hope that these improvements will bring you a low Swift compile time and that you will focus more of your time on productive tasks. If you liked my post, please don't forget to 💚 or share this post with your friends. Also, you can subscribe to my newsletter below and read more interesting Swift tutorials. That’s it from this tutorial and if it helped you please 👏 or share this story so others like you can find it. Thank you for your attention! 🚀 Check out my latest project: _This app is only available on the App Store for iOS devices. Increase your profits by following our professional BET…_apple.co VIP Sports Bet Tips & Scores on the App Store Read more of my writing on Medium: _Forget MVC, now!_hackernoon.com Introducing Clean Swift Architecture (VIP) _Many iOS apps use Google Maps. This is a very common feature, so I have decided to prepare an ultimate guide on the…_medium.freecodecamp.org Your ultimate guide to the Google Maps SDK on iOS, using Swift 4 _Custom UIView with XIB file is a very common practice in iOS Development. Custom UIView classes don’t contain XIB files…_medium.com SWIFT — Custom UIView with XIB file _A Swift tutorial that will make your app available in Spotlight search_hackernoon.com How to add Spotlight support to your iOS app _Understanding One-to-One and One-To-Many relationships_hackernoon.com Core Data Relationships _All you need to know about Auto Layout_hackernoon.com Understanding Auto Layout in Xcode 9 Subscribe to my Newsletter: