Brian Gilham

Engineering leader, husband, and father

xcode

Snapshot Tests + Blinking Cursors

It was Friday morning and I was already annoyed. One of our snapshot tests was failing. Randomly. Totally fine one minute, failure city the next. The snapshot was for a fairly benign login form. Present the view controller, call becomeFirstResponder on the first text field. What could possibly go wrong? Nothing in the test class seemed amiss. The build server was functioning normally. The test passed on my machine. Ready to give up, hours later, it finally dawned on me.

It was Friday morning and I was already annoyed. One of our snapshot tests was failing. Randomly. Totally fine one minute, failure city the next.

The snapshot was for a fairly benign login form. Present the view controller, call becomeFirstResponder on the first text field. What could possibly go wrong?

Nothing in the test class seemed amiss. The build server was functioning normally. The test passed on my machine. Ready to give up, hours later, it finally dawned on me.

The cursor. The damn blinking cursor.

For those not familiar, calling becomeFirstResponder on a UITextField immediately opens the keyboard and places a blinking cursor inside the text field. As it turns out, our snapshot test had been recorded when the cursor was visible. Well, maybe the build server was running a bit slower than usual, but that day the test ran when the cursor had blinked off. It was sheer luck we hadn’t run into it before.

Head, meet desk.


Disabling Slow Animations in the iOS Simulator

“There’s something weird going on with my simulator. Animations take about 100 times as long as they should. I have to wait 20 seconds to be able to click any buttons on a modal and then, once I do, I have to wait another 20 seconds for it to fade away.” There’s a funny — though extremely annoying — issue I see pop up on Stack Overflow and Reddit every few weeks.

“There’s something weird going on with my simulator. Animations take about 100 times as long as they should. I have to wait 20 seconds to be able to click any buttons on a modal and then, once I do, I have to wait another 20 seconds for it to fade away.”

There’s a funny — though extremely annoying — issue I see pop up on Stack Overflow and Reddit every few weeks. A developer fires up the iOS Simulator, eager to test their app, and discovers everything is moving really slowly. Modals take forever to appear and push animations slide across the screen at a glacial pace. It can be maddening. And unless you know what you’re looking for, it can be easy to miss the cause.

The iOS Simulator offers a debugging option titled — you guessed it — Slow Animations. If you’re working on a custom animation, it lets you see every frame and make sure everything is working as it should. The problem is: it’s incredibly simple to trigger accidentally. It uses a keyboard shortcut you might be familiar with: ⌘T. You think you’re opening a new browser tab but, surprise!

You can turn it off by navigating to Debug → Slow Animations, or simply hitting ⌘T once more.


How to Enable Developer Mode Using the Terminal

“When I used Xcode for the first time, it asked me if I wanted to enable Developer Mode, but I refused. Now I realize that it is really annoying to type my password so many times.” When you run Xcode for the first time on a fresh system, it asks if you’d like to enable Developer Mode. Developer Mode allows Xcode to execute common debugging tasks without constantly asking for your password.

“When I used Xcode for the first time, it asked me if I wanted to enable Developer Mode, but I refused. Now I realize that it is really annoying to type my password so many times.”

When you run Xcode for the first time on a fresh system, it asks if you’d like to enable Developer Mode. Developer Mode allows Xcode to execute common debugging tasks without constantly asking for your password. If you decline the prompt goes away, never to be seen again.

If — like our friend above — you grow tired of those damn password prompts, you might be hard-pressed to figure out how to enable Developer Mode later on. There used to be a button in Devices → My Mac, but recent versions of Xcode seem to have removed it.

Have no fear. The Terminal is here to save the day. Fire it up and enter:

DevToolsSecurity -enable

You’ll be prompted for your password. Enter it, and those pesky password prompts will be banished forever.