Apple’s example projects often have the variable names aligned, in addition to their type specification/general code indentation:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
As opposed to:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
Is there a shortcut to make this happen? (I don’t know what it would be called or else I could search the docs for it.)
The popular pretty-printer
uncrustifyhas at least a dozen different variable alignment parameters that you can specify in its config file. Tony Arnold’s project shows you how to useuncrustifyas an automator service (which means that you can access it from Xcode or any other editor). Robert Payne suggests using it from a shell script that you can incorporate into your build process.My guess is that Apple runs its examples through
uncrustifyor some other pretty-printer before publishing so that they’re all formatted using a common style. It may take some fiddling if you want to exactly reproduce Apple’s style, but at a minimum it should be pretty easy to get your variable declarations to align the way you want. It’s been a while since I played with all the options, but I’d start by looking at thealign_var_def_span,align_var_def_thresh, andalign_var_def_gapsettings.