If you have been looking for the same codes auto-format feature in the xCode like what you have in the other famous IDE such as Visual Studio.net or Eclipse, you will be disappointed. Unfortunately up to the latest version of the xCode (version 4.4), there aren’t any good auto-format feature built-in. The only one that you might be able to get is the basic code re-indent function.
In this post I will show you how to use the Uncrustify (http://uncrustify.sourceforge.net/) to add auto-format feature into the xCode.
STEP 1: We will need to install the Uncrustify on to your mac. The easiest way to install it is through the Homebrew.
* Install the Homebrew: Copy and paste this line of code to your command console:
ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
Next is to install the Uncrustify – just simply copy and paste this command into your command console:
brew install uncrustify
SETP 2: You will need to download this Automate workflow file
unzip and then move it to the ~/Library/Services/ folder. You can go the the folder that you downloaded the Automate workflow file and run the following commands:
mv Uncrustify-Objective-C.workflow.tar.gz ~/Library/Services/ cd ~/Library/Services/ tar zxvf Uncrustify-Objective-C.workflow.tar.gz
STEP 3: Download the pre set Uncrustify File for the Object-C: Unzip it > Rename it to .uncrustify_obj_c.cfg (Please note that there is a dot in front of the file name)and then move it to the ~/ folder by using the below commands:
mv uncrustify_obj_c.txt ~/.uncrustify_obj_c.cfg
* The format can be customised by modifying the uncrustify_obj_c.txt file before moving to the ~/ folder. Just open the txt file and modify the row that relevant to your style. Each setting has been commented, should be very easy to be customised.
STEP 4: Set up the keyboard short cut for autoformat feature.
Go to the “System Preferences – Keyboard – Keyboard Shortcuts – Service” and then look for the newly added services item “Uncrustify Objective-C”. Here is the place that you can add the shorcut for the autoformat feature. Please keep in mind that don’t use any shor cut that might conflict with what xCode already using. The recommended one: “Option + Command + O”, this combination shouldn’t conflict with the xCode pre-set ones.
Leave a Reply
You must be logged in to post a comment.