├── rename_classes.txt ├── rename-xcode-files.sh └── README.md /rename_classes.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rename-xcode-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT_DIR=. 4 | RENAME_CLASSES=rename_classes.txt 5 | 6 | #First, we substitute the text in all of the files. 7 | sed_cmd=`sed -e 's@^@s/[[:<:]]@; s@[[:space:]]\{1,\}@[[:>:]]/@; s@$@/g;@' ${RENAME_CLASSES} ` 8 | find ${PROJECT_DIR} -type f \ 9 | \( -name "*.pbxproj" -or -name "*.h" -or -name "*.m" -or -name "*.xib" -or -name "*.storyboard" \) \ 10 | -exec sed -i.bak "${sed_cmd}" {} + 11 | 12 | # Now, we rename the .h/.m files 13 | while read line; do 14 | class_from=`echo $line | sed "s/[[:space:]]\{1,\}.*//"` 15 | class_to=`echo $line | sed "s/.*[[:space:]]\{1,\}//"` 16 | find ${PROJECT_DIR} -type f -regex ".*[[:<:]]${class_from}[[:>:]][^\/]*\.[hm]" -print | egrep -v '.bak$' | \ 17 | while read file_from; do 18 | file_to=`echo $file_from | sed "s/\(.*\)[[:<:]]${class_from}[[:>:]]\([^\/]*\)/\1${class_to}\2/"` 19 | echo mv "${file_from}" "${file_to}" 20 | mv "${file_from}" "${file_to}" 21 | done 22 | done < ${RENAME_CLASSES} 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rename XCode Files 2 | ================== 3 | 4 | See [this Stack Overflow question](http://stackoverflow.com/questions/26165405/how-to-mass-add-a-2-letter-prefix-namespace-to-objective-c-project) for the source of this file. I've successfully used this a project but use at your own risk. 5 | 6 | ##Step 1: 7 | Add entries to "rename_classes.txt" file where each line contains a class name from/to pair separated by one or more tabs. Example: 8 | ``` 9 | MyClassA ZZMyClassA 10 | MyClassB ZZMyClassB 11 | MyClassC ZZMyClassC 12 | ``` 13 | 14 | ##Step #2: 15 | Copy and paste both files into the project directory, and run the shell script. 16 | 17 | Notes: 18 | 19 | - This script will update all references to classes found in the Project File, XIB files, storyboard files, .h & .m source files. 20 | - For each modified file, a backup file with the original contents will be created named "[filename].bak". 21 | - This script only renames .h & .m files. .xib files and Storyboards will need to be renamed by hand. 22 | - 'PROJECT_DIR' can be set to another directory if desired. 23 | - 'RENAME_CLASSES' should point to the file created in Step #1. 24 | --------------------------------------------------------------------------------