UIAlertAction considered longwinded
Even for Cocoa, adding actions to a UIAlertController is tediously verbose.
[alertController addAction:[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
doSomething();
}]];
The string "action" appears six times in the method call. There are only three kinds of actions. Wouldn't this be clearer?
[alertController addDefaultActionWithTitle:title handler:^(UIAlertAction *action) {
doSomething();
}];
Yes it would.
@implementation UIAlertController (Extras)
- (void)addCancelActionWithTitle:(NSString *)title
handler:(void (^)(UIAlertAction *action))handler {
[self addAction:[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleCancel
handler:handler]];
}
- (void)addDefaultActionWithTitle:(NSString *)title
handler:(void (^)(UIAlertAction *action))handler {
[self addAction:[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleDefault
handler:handler]];
}
- (void)addDestructiveActionWithTitle:(NSString *)title
handler:(void (^)(UIAlertAction *action))handler {
[self addAction:[UIAlertAction actionWithTitle:title
style:UIAlertActionStyleDestructive
handler:handler]];
}
@end