Clicky

iOS Dev Nugget 109 UIKeyCommand

.

Need to run a code review on your codebase? Hire me

Caleb Davenport has a great post on using UIKeyCommand to implement hardware keyboard shortcuts (now a broken link).

Beside its intended use, UIKeyCommand also presents a great way for you to add debugging shortcuts — that you remove when you ship — to your app. For example, you can assign a shortcut to print out the model details of your current screen or to run -exerciseAmbiguityInLayout if you use Auto Layout.

#ifdef DEBUG
//Subclass of UIResponder
- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (NSArray *)keyCommands {
    return @[
        [UIKeyCommand keyCommandWithInput:@"+" modifierFlags:0 action:@selector(callExerciseAmbiguityInLayoutRecursively)],
        [UIKeyCommand keyCommandWithInput:@"-" modifierFlags:0 action:@selector(displayModelData)],
    ];
}
#endif


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues