Web

Pro Tips on Behaviors in Xcode for iOS Developers

After the basic guide to Xcode published recently, I have another portion of tips and tricks for you. Today, I’ll discuss behaviours in Xcode. What they are and how to use them, with handy examples. Let’s roll!

Let’s start from the beginning, shall we? Xcode behaviours allow you to define a set of actions when a specific event occurs. There are practically lots of them (just go to Settings -> Behaviours and you will see the full list), but let me name a few basic ones:

  • start a build,
  • pause on a breakpoint,
  • print out to console,
  • complete build,
  • custom actions triggered with defined key shortcuts.

For each event, you can define a custom group of settings like:

  • open a new tab or window,
  • play an alert sound,
  • speak an announcement,
  • hide/show a navigator,
  • hide/show a toolbar, utilities, debugger,
  • show an editor in the Assistant or Standard mode,
  • launch scripts,
  • and even bounce Xcode icon in Dock 🙂

Before you start to customise your Xcode, let’s create a custom tab first.

Custom tabs in Xcode

It’s really simple to do, just press CMD + t and double tap on tab’s name.

Let’s create 3 tabs – Coding, Console, and Debug:

Alright! Now, time to get your hands dirty – make Xcode behave like you want it to.

Console

Go to Settings -> Behaviours and choose Running -> Generate outputs. For starters, you’ll make use of your first custom tab “Console”:

Now, whenever your code generates some output, Xcode will open/create a tab named “Console” in a separate window with a full-screen Debug area. How cool is that! If you use the second monitor, just place it on the second display and all logs will be now easy to follow in this particular window. If you prefer to work on a single screen instead of a separate window, pick the active window – then the tab will open in your current Xcode window.

Debugging

Ok, now that you’ve got your Console covered, let’s prepare custom behaviours for the Debugging mode when your app pauses on a breakpoint or error. In such a case, I would like to see the Debug navigator, a debugger with variables (as I already have a window with a console), and, of course, a tab with the code and breakpoints. This time we will play with “Debug” tab and Running -> Pauses behaviours

Now, whenever Xcode hits a breakpoint, you will get this all-inclusive view:

No more annoying interruptions into your current coding tab! Same as with the Console tab, you may decide whether to open it in a separate window or in the active one.

Coding

That’s your final custom tab. I would like it to be designed to let me focus on coding. And all I need for coding is an editor. In my case, the Assistant Editor. Go to Settings -> Behaviors and choose Running -> Completes.

Now, whenever a build stops, I would like to see only the code I’m working on at the particular moment.

Shortcuts

Same as for events, you can set up behaviours with custom key shortcuts. When I work on my project, I usually write code or play with Storyboards. These two modes require different setups. Go to Settings -> Behaviours and choose Custom -> tap + and click the Command icon to assign a friendly shortcut that will trigger your newly setup behaviour.

and a slightly different one for working with Storyboards:

Now, whenever I want to focus on writing code, I will only see the code editor in the Assistant Mode and when I need to play with storyboards I will get the Standard Editor with utilities.

Behaviours are really powerful and highly customisable tools, so play around with them and find out what suits you best.

Subscribe to our newsletter

Want to receive a fortnightly round up of the latest tech updates? Subscribe to our free newsletter. No spam, just insightful content covering design, development, AI and much more.

Most Popular

5 ½ Greatest Things About Remote Work

5 technology trends likely to continue booming in a ...

Thinking of building an app in React Native? Learn f...

You may also like these posts

Start a project with 10Clouds

Hire us