Thursday, 11 June 2009

XCode trailing whitespace

For all the other trailing-whitespace-haters out there, if you would like to remove trailing whitespace from all the files in your XCode project, do a global search replace (Shift+⌘+F) for the following regular expression:

[ \t]+$

In older versions of XCode you have to select all the results before hitting "Replace".

6 comments:

  1. check this out! its a plugin from google toolbox for mac that deletes end line whitespace, and adds eof line if there isnt any.

    http://code.google.com/p/google-toolbox-for-mac/wiki/GTMXcodePlugin

    ReplyDelete
  2. GTM Xcode Plugin is a godsend! Thanks for the link!

    ReplyDelete
  3. the problem with the google plugin for xcode is that it corrupts your undo buffer when it fixes your trailing whitespace. frustrating.

    ReplyDelete
  4. I've found that this particular regex also matches lines that *only* have whitespace, at least in Xcode 3.2.6. Since I'd prefer to only remove trailing whitespace only on lines that also have non-whitespace characters, I needed something else.

    If you replace (?<=\S)[ \t]+$ with an empty string, it will match only lines that have trailing whitespace after one or more non-whitespace characters. Thanks for posting this tip!

    ReplyDelete
  5. BTW there's an Xcode 4 version of the GTM plugin now. Checkout http://code.google.com/p/google-toolbox-for-mac/wiki/GTMXcodePlugin

    ReplyDelete
  6. Beginners particularly love this game because of its simplicity. If you name you will first need to undergo the standard steps of attending to the proper department, which can take a couple of minutes. When we spoke to the reps they have been all very pleasant, they usually managed to solve our issues instantly. You only have to confirm your 카지노사이트 account after which they may help you out together with your issues.

    ReplyDelete