Skip to content

Instantly share code, notes, and snippets.

@jazzychad
Created October 8, 2013 20:18
Show Gist options
  • Save jazzychad/6890924 to your computer and use it in GitHub Desktop.
Save jazzychad/6890924 to your computer and use it in GitHub Desktop.
Extracts private methods from a .m class file and creates a Class+Private.h class extension - somehow turning this into an Xcode plugin would also be cool.
#!/bin/bash
# change PREFIX to match whatever you use to denote private
# methods internally in .m files
# e.g.
# - (void)_privateMethod
PREFIX="_"
if [ $# -eq 0 ]
then
echo "usage: $0 <class_file>.m"
echo
echo "outputs a Class+Private.h file with internal private method"
echo "signatures as determined by the defined method prefix"
exit 1
fi
if [ ! -f $1 ]
then
echo "$1 is not a file. Aborting."
exit 1
fi
FILE=`basename $1`
CLASS="${FILE%.*}"
OUTFILE="$CLASS+Private.h"
echo "#import \"$CLASS.h\"" > $OUTFILE
echo >> $OUTFILE
echo "@interface $CLASS ()" >> $OUTFILE
echo >> $OUTFILE
egrep "^[-+][ ]?\(.*\)[ ]?$PREFIX" $1 | awk '{print $0 ";"}' | sort >> $OUTFILE
echo >> $OUTFILE
echo "@end" >> $OUTFILE
cat $OUTFILE
@seivan
Copy link

seivan commented Mar 29, 2014

Thanks. I could really use this.

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