Xcode is an essential tool for developing iOS and Mac OS applications. However, compared with IDE such as Eclipse, xcode provides fewer auxiliary functions, in eclipse, you only need to press Ctrl + Shift + F to format the Java code very well. In xcode, only re-indent (CTRL + I) is used to adjust indentation, which is obviously not enough.
To complete code formatting, you must use tools such as uncrustify. Furthermore, we can use automate to configure a service for text and add shortcuts to indirectly implement the Code formatting function with the same effect as eclipse in xcode.
First install the uncrustify tool. There are many installation methods. homebrew is recommended for installation. If no homebrew exists on the machine, run the following command to install it:
https://raw.githubusercontent.com/Homebrew/install/master/install
If the above changes, you can go to the official home page http://brew.sh/index_zh-cn.html to compare and update.
After homebrew is installed, run the following command to install uncrustify:
brew install uncrustify
Then download the workflow package that has been configured in the attachment in the connection.
, Copy ~ /Library/services/, and decompress it. Unzip the command:
mv Uncrustify-Objective-C.workflow.tar.gz ~/Library/Services/cd ~/Library/Services/tar zxvf Uncrustify-Objective-C.workflow.tar.gz
Use the uncrustify configuration file for objective-C language in the downloaded package above to move ~ /Directory and rename it to. uncrustify_obj_c.cfg. Note that the destination file name is preceded by a dot.
If the preceding steps have been completed successfully, right-click a piece of code in xcode and an uncrustify objective-C service should be available in services. After the selection, you can format the code. Of course, it is too troublesome to click the mouse each time. Configure the shortcut key below.
Click the apple icon in the upper-left corner of the screen, select system preference settings-keyboard-Shortcut Key-services, find the newly added service uncrustify objective-C in the text partition, and add the shortcut key to the service. Do not conflict with other shortcut keys in xcode. We recommend that you set it to OPT + cmd + letter O.
In this way, in xcode, run cmd + A to select all the code, and then use opt + cmd + O to format the code. The overall effect is basically the same as that of Eclipse.
How to organize code using shortcuts in xcode