Breaking news! I just launched Coparrot, a no-install and no-configuration mock server for mobile and web developers, on Product Hunt!
Please check it out and give it some love ❤️!

nico.fyi

Xcode Tips and Tricks

May 31, 2021 in articles

In this article I will share some tips and tricks to use Xcode that I discussed with fellow Indonesian iOS developers at the last session of Belajar Swift Bareng Mingguan.

Quickly open files

Use cmd+shift+o keyboard shortcut to quickly open files. Once the search field appears, you can start typing the name of the file that you want to open. Since it uses fuzzy search, you don’t even need to type the exact filename. To open the file, you can press Enter key, or option+Enter to open the file in the Assistant Editor.

Toggle SwiftUI Previews

Use cmd+option+Enter to quickly hide and show the SwiftUI Previews.

Resume the SwiftUI Previews

Xcode pauses the SwiftUI Preview from time to time. Use cmd+option+P to quickly resume the SwiftUI Previews.

Show the file in the Project Navigator

Use cmd+shift+J to quickly show the file in the project navigator.

Go to Line

Use cmd+L to quickly go to a certain line.

Toggle the Debug Area

Use cmd+shift+y to quickly show and hide the Debug area.

Show Document Items

Assign a keyboard shortcut to quickly show the document items. In my case, I use cmd+§ because I’ve never used it ever.

Fold and Unfold

Use cmd+option+right arrow and cmd+option+left arrow to quickly fold and unfold codes.

Edit current scheme

Use cmd+< to quickly open the Edit Scheme window.

Fix identation

Use ctrl+i to quickly fix the identation of your code.

Add Documentation

Use cmd+option+/ to quickly add documentation to a function, class, etc. You can then use Markdown in the documentation.

Open the Project’s directory in the Terminal

Assign any keyboard shortcut to quickly open the project in Terminal. In my case, I use cmd+P because the default it to print and let’s be honest, we’ll never print our source code.

To be able to do this, you need to create a small shell script with the following content:

#!/bin/bash
open -a Terminal "`pwd`"

Then add a custom behaviour in the Xcode Preferences.

Double the strings

Add -NSDoubleLocalizedStrings YES to the Arguments Passed On Launch in the scheme to double the texts shown in your app.

Multiline cursors

Quickly edit multiple lines by pressing shift+control+option when clicking the line.

Select Next Occurrences

Use cmd+option+E to quickly select next occurrences of selected text and cmd+control+E to select all occurrences in the current scope.

One last thing…

And just for fun, you can make your Mac say a custom message when a build succeeded or failed. It can be pretty fun especially if you’re bored working alone from home 🤣

To be able to do this, you need to create a small shell script as follows.

#!/bin/sh

say -v Serena "Great job! Build succeeded!"

You can change the voice by replacing Serena in the script above with other voices. You can find the list of available voices by going to System Preferences -> Dock & Menu Bar -> Clock. Check the Announce the time: then click the Customise voice...

available voices


Nico Prananta

Articles, drawings, and codes by Nico Prananta, a software developer (iOS and web) and digital artist (for fun!) in Zürich, Switzerland. I'm on Twitter.

RSS Feeds
plus62.dev

Announcement

For Indonesian iOS Developers! Gabung yuk tiap hari Sabtu jam 16:00 WIB di Belajar Bareng Swift Mingguan bareng temen-temen iOS developer di Swift Study Group Indonesia.