XCode Tip: Block Select Mode

Sometimes, when you comment something out in XCode, uncommenting using the standard Command + Slash might not work (it just adds another row of // commented out code, instead of uncommenting!). Previously, I just manually removed the // from each line of code. But yesterday, I learned that there is another, better / cooler solution out there!

Option + Drag lets your select as many columns of code as you want vertically!

Enjoy the article? Join over 14,500+ Swift developers and enthusiasts who get my weekly updates.

  • Nick H

    Wow. That is so useful. Thanks for that find.

    One thing to note that I found, it currently does not work in playgrounds. It looks like it will, it selects them all, but when you let go of the mouse button, it just selects the topmost line’s selection.

    It works great in normal Xcode though 🙂

  • Thanks, didn’t know about it.

  • Joanna Carter

    – (void)composerNumeroPhone:(NSString *)numeroPhone
    {
    //*
    NSString* numPhone = [NSString stringWithFormat:@”telprompt:%@”, numeroPhone];

    NSURL *numPhoneURL = [NSURL URLWithString:numPhone];

    if ([[UIApplication sharedApplication] canOpenURL:numPhoneURL])
    {
    [[UIApplication sharedApplication] openURL:numPhoneURL];
    }
    //*/
    }

    To “activate” the comment block, simply remove the first slash from the opening marker. This works with Objective-C but doesn’t seem to work with Swift

    • Joanna Carter

      But, for Swift, the following does seem to work

      – (void)composerNumeroPhone:(NSString *)numeroPhone
      {
      //*
      NSString* numPhone = [NSString stringWithFormat:@”telprompt:%@”, numeroPhone];

      NSURL *numPhoneURL = [NSURL URLWithString:numPhone];

      if ([[UIApplication sharedApplication] canOpenURL:numPhoneURL])
      {
      [[UIApplication sharedApplication] openURL:numPhoneURL];
      }
      ///**/*/
      }

  • Steve Rosenberg

    Works great. Previously I selected the block, right click then Structure|Uncomment Selection

  • Joseph Collins

    Thanks Natasha! Also if you command + option + drag you can do some super selective block editing.

    • Rohan

      Woah! Great tip.