Skip to content

Instantly share code, notes, and snippets.

@fe9lix
Created February 16, 2016 19:08
Show Gist options
  • Save fe9lix/94ac697203b8c823209d to your computer and use it in GitHub Desktop.
Save fe9lix/94ac697203b8c823209d to your computer and use it in GitHub Desktop.
Xcode: Remove header comments in Swift files
find . -type f -name "*.swift" -not -path "./Pods/*" -exec sed -i '' -e '1,/^import/{/^\/\/.*/d;}' -e '/./,$!d' {} \;
@Lukaz32
Copy link

Lukaz32 commented Aug 3, 2017

It also removes my pragma mark outside my class implementation, such as: // MARK: UITableViewDelegate
Is there any way I could make it keep them?

Thanks

@stijnergeerts
Copy link

Did you find a solution for this?

Copy link

ghost commented Oct 8, 2019

Amazing!

@NikSativa
Copy link

👍

@anivaros
Copy link

Here is my version of script with fixed problem from comments above

find . -type f -name "*.swift" -not -path "./Pods/*" -exec sh -c '
  if ! head -n 1 "$1" | grep -q "^[A-Za-z]"; then
    sed -i "" -e "1,/^[A-Za-z]/{
      /^\/\/.*/d;
      /^$/d;
    }" "$1"
  fi
' sh {} \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment