Strip Trailing Whitespace in Xcode 4 Tuesday, November 01, 2011, by Sebastian Dwornik
XCode 4 is great. But it has some annoyances. One of which is inserting whitespaces in your code as if they were breadcrumbs to mark your path in case you get lost.
Thanks to Brian Cardarella for originally working this out, I simply modified his script to handle *.h and *.m files.
Simply create your own shell script (e.g. stripWhitespace.sh) and insert the following contents:
#!/bin/sh
find . -name "*.[hm]" -type f -print0 | xargs -0 sed -i '' "s/[[:space:]]*$//"
Lastly set a 'Behavior' in XCode to run the script with a shortcut.
Voila!
It will clear all of the whitespace within your entire projects directory for all files ending in *.h and *.m .