Monday, April 27, 2020

Changing XCode to create .h files instead of .hpp files

When we create files in C++ project in XCode It results in creation of .hpp files which are not used as much as .h files

/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/Source/C++\ File.xctemplate/WithHeader

Change permission of ___FILEBASENAME___.hpp to edit it using the below command
sudo chmod 666 ___FILEBASENAME___.hpp


Now open the file ___FILEBASENAME___.hpp in nano by using the below command on terminal
nano ___FILEBASENAME___.hpp

Replace hpp in file with h
Press Ctrl + O to overwrite and save the file
Press Ctrl + X to exit nano

cd ..

Change folder permissions to allow to rename file
sudo chmod -R ugo=rwx WithHeader/

Finally rename file
mv ___FILEBASENAME___.hpp ___FILEBASENAME___.h

Similarly for ___FILEBASENAME___.cpp we need to replace hpp with h

sudo chmod 666 ___FILEBASENAME___.cpp
nano ___FILEBASENAME___.cpp

 Replace hpp in file with h
Press Ctrl + O to overwrite and save the file
Press Ctrl + X to exit nano


Tada! Relaunch Xcode to get .h files on creating .cpp files in project