Adding a Delete Line hotkey in Xcode

When I switched from eclipse to sublime text 2, the first hotkey I moved over was cmd+d to delete a line. I use it pretty heavily.  After using Xcode for a few months it was driving me crazy that it didn't have delete line as an option under hotkeys. Thanks to stackoverflow for the solve. To add a new custom key binding, we have to edit the Key Binding plist file: (close Xcode)

sudo vi /Applications/

Add this text just ABOVE the close of the <dict> at the bottom of this file:

      <key>Delete Current Line In One Hit</key>
      <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>

Note that:

  • This is inside the existing <dict> so there is a </dict></plist> after this
  • This associates the named action "Delete Current Line In One Hit" to the three key actions in the string. I played around with different options here to get the right combination. For instance, if you try moveToBeginningOfLine, deleteToEndOfLine instead of vice versa, then using it on empty lines will delete the line and the entire next line. Which is unpleasant Save this and open XCode
  1. Open XCode Preferences
  2. Select Key Bindings
  3. Click on All
  4. In the SEarch box type "Delete" and search for "Delete Current Line in One Hit"
  5. Add your new binding. I use cmd+d, so I had to map duplicate to something else first

Animate an AdWhirlView from the Bottom of the Screen

If you are using AdWhirl and want the ad to slide in from the bottom of the screen when your View loads, use this snippet:

- (void)viewDidLoad
    [super viewDidLoad];
    AdWhirlView *adWhirlView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
    adWhirlView.delegate = self;
    adWhirlView.frame = CGRectMake(0, 430+kAdWhirlViewHeight, kAdWhirlViewWidth, kAdWhirlViewHeight);
    [self.parentViewController.view insertSubview:adWhirlView belowSubview:self.view];

    [UIView beginAnimations:@&quot;AdWhirlIn&quot; context:nil];
    [UIView setAnimationDuration:.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    adWhirlView.frame = CGRectMake(0, 430, kAdWhirlViewWidth, kAdWhirlViewHeight);
    [UIView commitAnimations];

Adding Done and Cancel buttons to an iOS number pad

There are some cases when you may want to have a "Done" or "Cancel" button on an iOs number pad when editing a text field. This doesn't come by default, but is easy to add. See the example snippets below, or check out the code on github.

Sample Usage:

//In the view controller that's going ot use the component, put this in the header after the class being extended.

// Then instantiate your toolbar component where it's needed
DoneCancelNumberPadToolbar *toolbar = [[DoneCancelNumberPadToolbar alloc] initWithTextField:textField];
toolbar.delegate = self;
textField.inputAccessoryView = toolbar;

// Finally, implement the following two delegate methods

#pragma mark - DoneCancelNumberpadToolbar delegate
-(void)doneCancelNumberPadToolbarDelegate:(DoneCancelNumberPadToolbar *)controller didClickDone:(UITextField *)textField
    NSLog(@&quot;%@&quot;, textField.text);

-(void)doneCancelNumberPadToolbarDelegate:(DoneCancelNumberPadToolbar *)controller didClickCancel:(UITextField *)textField
    NSLog(@&quot;Canceled: %@&quot;, [textField description]);


#import <UIKit/UIKit.h>

@class DoneCancelNumberPadToolbar;

@protocol DoneCancelNumberPadToolbarDelegate <NSObject>

-(void)doneCancelNumberPadToolbarDelegate:(DoneCancelNumberPadToolbar *)controller didClickDone:(UITextField *)textField;
-(void)doneCancelNumberPadToolbarDelegate:(DoneCancelNumberPadToolbar *)controller didClickCancel:(UITextField *)textField;


@interface DoneCancelNumberPadToolbar : UIToolbar
    UITextField* textField;


#import &quot;DoneCancelNumberPadToolbar.h&quot;

@implementation DoneCancelNumberPadToolbar

@synthesize delegate;

- (id) initWithTextField:(UITextField *)aTextField
    self = [super initWithFrame:CGRectMake(0, 0, 320, 50)];
    if (self) {
        textField = aTextField;
        self.barStyle = UIBarStyleBlackTranslucent;
        self.items = [NSArray arrayWithObjects:
                      [[UIBarButtonItem alloc]initWithTitle:@&quot;Cancel&quot;
                      [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                   target:nil action:nil],
                      [[UIBarButtonItem alloc]initWithTitle:@&quot;Done&quot;
        [self sizeToFit];

    return self;

    [textField resignFirstResponder];
    textField.text = @&quot;&quot;;
    [self.delegate doneCancelNumberPadToolbarDelegate:self didClickCancel:textField];

    [textField resignFirstResponder];
    [self.delegate doneCancelNumberPadToolbarDelegate:self didClickDone:textField];

@property (nonatomic, weak) id <DoneCancelNumberPadToolbarDelegate> delegate;

- (id) initWithTextField:(UITextField *)textField;


Special thanks to [akozl ik]( el_buttons_to_an_ios_number/c5v4rpt) for the help with delegates.