Some of the lesser-known features and tricks of Xcode

Besar
Besar
Jul 31 · 4 min read
Photo by Jefferson Santos on Unsplash

Xcode is an integrated development environment (IDE) for macOS containing a suite of software development tools developed by Apple for developing software for macOS, iOS, iPadOS, watchOS, and tvOS.

Xcode has some shortcuts that make your everyday life easier, like Open Quickly (⇧ + ⌘ + O) or Clean Build (⇧ + ⌘ + K) 🧹.

But there are some really cool features that are not very known on the iOS development community. I’ve met a lot of fellow iOS developers that have been coding for years, yet they don’t try to get the most out of Xcode. Thus I wanted to write an article where I would cover a bunch of lesser-known useful hacks that I have personally been using for the past few years that will improve your workflow.


Hack #1: Creating Your Swift Model

You want to create your Swift model based on your database model instead of writing every single column one by one. You can do this. Simply use ⌥ + Hold left mouse to select your fields, use and arrows to navigate through lines, and use and arrows to navigate through words :


Hack #2: Creating a Constructor

The same thing applies when you want to create a constructor. Sure it would be great to have a feature like IntelliJ has, which helps you generate a constructor or getters/setters on ^ + Enter combination, but since Xcode doesn’t have that, it doesn’t mean that you have to generate your init by writing every property one by one, thrice. Instead you can use the same hack mentioned above, with the same instructions 👷‍♂️:


Hack #3: Debugging

With expression command e, we are able to run swift code and do code injections while debugging. For example, we can change the label text color or the button title, and much more.

For example, if we want to change the button title:

(lldb) e saveButton.setTitle("Saved", for: .normal)

Step is also a very useful command. It helps you to Step Over while debugging, stepi is used for “Step Into”.

We can disable/enable all breakpoints by the help of those commands:

(lldb) breakpoint enable
(lldb) breakpoint disable

And also we can continue execution:

(lldb) continue

If you continue writing commands on the debug area and you want to clean the console from previous commands, you can do that without clicking the trash button on the right bottom corner. Instead you can use ⌘ + k. If you are done with the debugging area, you can hide it by using ⇧ + ⌘ + t .

While debugging

Hack #4: Navigating Through Code and Files

Going to a certain line of code of a particular file is pretty straightforward by the help of Open Quickly (⇧ + ⌘ + O). When the search window appears, after writing the name of the file and the number (of the line you want to go to) separated by a colon, you get to your destination, e.g:

BaseTableViewController:250

This takes you to the line # 250 of BaseTableViewController class.

In case you want to go to a particular line of code on the existing file, you can just use ⌘ + l, and when the input window appears, add the line number and you are there.

Use ^ + 6 to open the list of attributes and methods where you can start typing immediately to find a particular method or attribute by its name.

Moving one or more lines of code, up or down, without needing to do cut and paste, just select the lines you want to move and use:

⌥ + ⌘ + [ — To move line(s) up ⬆️

⌥ + ⌘ + ] — To move line(s) down ⬇️

When you want to find the currently working file on the Project Navigator, use ⇧ + ⌘ + j and the left pane will appear with your file selected. This is very handy when you have a lot of files on your project and navigation becomes hard.

Photo by Helloquence on Unsplash

Thanks for dedicating your time to reading this. Xcode has way more features than those mentioned above—put down in the response section which one you use most often!

Found this article useful? Follow me (Besar) on Medium!

Better Programming

Advice for programmers.

Besar

Written by

Besar

iOS Developer - Oslo, Norway

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade