Facebook’s New “Tweaks” Library Lets Developers Fine-Tune Their iOS Apps On The Fly

Let’s say you’re building an iOS app.

Your iOS app has lots of little animations, and you (or your designers) want to get the timing on those animations just right. Should that fancy expanding-drawer effect take half a second, or three-fourths of a second?

Normally, a developer would take a guess at the timing that seems right, compile their app, test, change, recompile, rinse, lather, repeat. Given that complicated apps can take quite a while to compile, those little changes start to gobble up your time. You start to hate the progress bar.

Why recompile for something so simple? And what if the person perfecting the timing is more of a designer than a coder? Should they have to dig about the source just to change the animation speed?

There are all kinds of shortcuts, of course. You could, for example, tie the animation speed’s variable to an on-screen slider, which any user running a pre-release copy of your app could adjust on-the-fly — but you’d have to manually code that in, and remember to take it out before release. It’s a completely valid option — but it’s not very standardized, and each thing you want to be able to change on-the-fly means extra lines of code. It could be better.

Facebook thinks they’ve done it better.

They’ve just released a library called “Tweaks”, which lets developers easily mark certain things — like the timing of an animation, or the color of a button, or the translucency of an image — as one that can change on-the-fly once the app is actually running on the device. The library tucks all of these tweakable variables into a snazzy little hidden settings screen, then cleans it all up when it’s time to actually release the app.

As Facebook puts it:

The best way to improve an app is to use it every day. Even when ideas can be tested out in advance — for example, with Origami — it can still take some time with the app to see how it works in practice.

Occasionally, it’s perfect the first try. Sometimes, the idea doesn’t work at all. But often, it just needs a few minor adjustments. That last case is where Tweaks fits in. Tweaks makes those small adjustments easy: with no code changes and no computer, you can try out different options and decide which works best.

When an application is compiled in debug mode, shaking the phone would bring up a screen that allows the user to muck with any settings the developer has exposed. When it’s compiled into its normal “release” mode (as in, when it’s prepped for the App Store), the “Tweak” value is replaced with a normal, unchangeable value, and that hidden configuration screen disappears for good. There’s very little extra code to add in, and very little to forget to remove.

The only real change a developer would have to make in their code: instead of hardcoding a value, they set that value to be a “Tweak”. In code speak, instead of:

CGFloat animationDuration = 0.5

You’d use:

CGFloat animationDuration = FBTweakValue(@”Category”, @”Group”, @”Duration”, 0.5);

So what’s the point?

For developers, it means being able to fine-tune applications faster and with less code. As an added bonus, it lets any of their designers who might not love to code help figure out the best settings without having to pop into the source or pester the dev team for a million new builds. Everybody wins! Hurray!

Facebook has released Tweaks on GitHub (for free under a rather non-restrictive BSD license) right over here.