NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

24 Quick Xcode Tips

Write code faster, build better tests, and navigate around projects more efficiently.

Paul Hudson       @twostraws

Xcode is a huge program, and if you can learn one or two new tips that help you work more effectively you can save hours of time every week.

In this article I want to walk you through 24 quick Xcode tips that help you write code faster, build better tests, and navigate around large projects more efficiently – there’s something for everyone!

  • This article is also available as a video if you prefer. The content is the same, so use whichever is easiest for you.
Hacking with Swift is sponsored by RevenueCat

SPONSORED Building and maintaining in-app subscription infrastructure is hard. Luckily there's a better way. With RevenueCat, you can implement subscriptions for your app in hours, not months, so you can get back to building your app.

Try it for free

Sponsor Hacking with Swift and reach the world's largest Swift community!

1. Generating class initializers

Swift can synthesize memberwise initializers for structs, but not for classes. Fortunately, Xcode can generate the code for us: select your class name, then go to the Editor menu and choose Refactor > Generate Memberwise Initializer. Done!

2. Environment overrides

When building software, it’s important to make sure your app works for everyone. One great way to do that is with Xcode’s environment overrides panel, which lets you adjust Dynamic Type size, accessibility options, and appearance all in one place.

3. Selecting blocks of code

You probably already know that you can click after any open { or close } brace to have Xcode highlight its matching brace, but another useful tip is that you can double click a brace to select the entire block of code it contains.

4. Checking our spelling

Xcode can check if your spelling is correct, and it even understands that camelCaseNames should be treated as separate words. Go to the Edit menu and choose Format > Spelling and Grammar > Check Spelling While Typing, and Xcode will check your code for typos.

5. Fixing all issues

If you have a Swift file with many errors, you can use Xcode’s fix-its to try to correct them one by one. But a faster way is to go to the Editor menu and choose Fix All Issues to apply fix-its all at once. (Make sure and double-check which changes were made!)

6. Deleting search results

When you search using Xcode’s find navigator, you can click to view individual results and make any changes you want. But when you’re done, I recommend you hit Backspace to remove the search item from the results, so you can see which results you have left to check.

7. Resuming the SwiftUI canvas

This is the simplest tip I know, but it will save you time if you don’t already know it. Whenever you see Automatic Preview Updating Paused in your SwiftUI canvas, press Opt+Cmd+P to resume previewing. Alternatively, use Opt+Cmd+Return to hide the canvas completely.

8. Tiling the simulator

If you frequently move from Xcode to the simulator, tile them side by side. With the simulator active, go to the Window menu and choose Tile Window To Right Of Screen, then select Xcode on the left. You can adjust the split so the simulator sits snugly on the right.

9. Expanding autocomplete

Xcode has great code completion built right in, but sometimes as you scroll through the options you might find the names are too long to fit. Fortunately, you can just grab the edge of the autocomplete popup and drag it as wide as you want!

10. Quickly toggling breakpoints

Breakpoints are great for debugging – place them by selecting a line number, or remove them by right-clicking and choosing Delete Breakpoint. You can also remove one by dragging it away, but a fast method is to use Cmd+\ to toggle a breakpoint on the current line.

11. Randomizing test order

Sometimes the output from one test affects the input for another. Xcode has a solution: go to the Product menu, hold down Option, then click Test. Inside the Info tab, click Options then check Randomize Execution Order to run tests in a different order every time.

12. Filtering the jump bar

Xcode’s jump bar (Ctrl-6) is the best way to jump around long files quickly, letting you browse all properties and methods in your file. For longer files, start typing with the jump bar open and Xcode will filter it – a trick that also works for device selection.

13. Generating an interface file

It’s common to want to get an overview of how some code works. If you press Ctrl+Cmd+Up Xcode produces a generated interface, showing properties, function signatures, and comments. If you press it again, Xcode takes you to the tests for that file if they exist.

14. Adding comments quickly

One of my most commonly used Xcode shortcuts is Cmd+/ to toggle comments for the current line or selection, but another useful one is Option+Cmd+/ – press that directly before a method to have Xcode generate a documentation comment, including its parameters.

15. Finding files faster

As your projects grow, it gets harder to use the project navigator to find something. There are two solutions: one is to right-click on any file group and choose Sort By Name to arrange them A-Z, and the second is to type into the filter box at the bottom.

16. Seeing source changes inline

Xcode can handle source changes right in its editor. To try it, enable Show Source Control Changes in Xcode’s preferences, then make a change. On the left you’ll see a blue bar, but if you click it and select Show Change Xcode shows you the old and new code inline.

17. Finding code in the minimap

Xcode’s minimap helps us browse long files – enable it from Editor > Minimap. As you hover your mouse over it, the minimap tells you the name of the method you’re over. You can also hold Cmd to reveal the names of everything, then click on a name to jump to it.

18. Re-run your last test

It’s common to write failing tests, particularly when using TDD. Fortunately, Xcode has a keyboard shortcut to run only the last test, which is faster than running everything: Ctrl+Opt+Cmd+G. Jon Reid has a name for this making it easier to remember: “smash go!”

19. Remapping unhelpful keys

Some great shortcuts (e.g. Shift+Cmd+O for Open Quickly) are next to useless shortcuts (Shift+Cmd+P, for the never times you want to print code.) It takes only seconds to remove unhelpful keys, and you can even remap things like Cmd+P to resuming SwiftUI's preview.

20. Upgrading your searches

All the titles in Xcode's find navigator can be changed: Find can Replace, Text can be references or regular expression, and Containing can be matching, starting, and more. You can also click the magnifying glass to see recent searches – selecting one repeats it.

21. Reindenting code

If you’ve copied code from elsewhere, such as Hacking with Swift or Stack Overflow, there’s a good chance you’ll paste in something with incorrect indentation. Xcode can fix this with one shortcut: select the code you want to fix, then press Ctrl+I to reindent it.

22. Testing in-app purchases

You can test in-app purchases without App Store Connect. Make a new StoreKit Config File, and add your IAP. Now go to the Product menu, hold down Option, and click Run. From the Options tab of the window, change StoreKit Config, and now you'll use the test IAP.

23. Exploring build options

There are many settings to control how Xcode builds your code, but it’s hard to remember what they all do. Fortunately, you can select one and use the Quick Help inspector to see documentation for most settings, or hold Option and double-click to get inline help.

24. Pinning previews

The canvas is a great way to preview layouts as you work, but it’s harder to use when one view is split across files. To make things easier, use the pin at the bottom to keep the current preview active, allowing you to change one file while previewing another.

Looking for more?

What are your favorite Xcode tips? Tweet me @twostraws and let me know!

And if you’re keen to learn even more Xcode tips, I have other articles that will interest you:

  1. Xcode tips and tricks – part one
  2. Xcode tips and tricks – part two
  3. Xcode tips and tricks – part three
  4. Xcode tips and tricks – part four
Hacking with Swift is sponsored by RevenueCat

SPONSORED Building and maintaining in-app subscription infrastructure is hard. Luckily there's a better way. With RevenueCat, you can implement subscriptions for your app in hours, not months, so you can get back to building your app.

Try it for free

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

About the author

Paul Hudson is the creator of Hacking with Swift, the most comprehensive series of Swift books in the world. He's also the editor of Swift Developer News, the maintainer of the Swift Knowledge Base, and a speaker at Swift events around the world. If you're curious you can learn more here.

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.