Although in the early stages of project creation and team building, we have set the public agreement and some specifications, and since our code is version control through Git, the Web directly supports the markdown format of the Readme file, you can always see the latest version, But this specification can only rely on personal consciousness, or through the code review to solve, and when the code review, you also embarrassed always write a bunch of such as "here to add a space", "where to add line" comment? If no matter, over time, because everyone's habits are different, the code presents a variety of styles, it does not look like a mature team made products.
To compensate for the Xcode code formatting of the short board, we chose to introduce a third-party plugin:Clangformat.
Specific process:
1. Install package Manager First (you can also skip the 2nd step)
Website address: Https://github.com/supermarin/Alcatraz
Installation method: In Terminal input: Curl-fssl https://raw.github.com/supermarin/Alcatraz/master/Scripts/install.sh | Sh
After the installation is successful, you can see the "package Manager" in the Xcode window.
2. Installing Clangformat
GitHub Address: Https://github.com/travisjeffery/ClangFormat-Xcode
Installation method: Search and install directly in the Package Manager, if you do not want to install the Package Manager, you can directly clone the above GitHub code, compile, run in Xcode, and then restart Xcode.
3. Configure Clangformat
Although the Clangformat itself has some standardized code formatting schemes built in, it can be customized as well, and we've adopted a custom approach.
Specifically, create a ". Clang-format" file in the project catalog or workspace directory, and add parameters similar to the following:
# Base Style basedonstyle:llvm# indent width indentwidth:4# parentheses line wrapping breakbeforebraces:attach# Case indentation indentcaselabels:true# for ifallowshortifstatementsonasingleline:true# switch support line The indentation width of the block for OC is objcblockindentwidth:4# for OC, and the property name is followed by a space objcspaceafterproperty:true# the length of each line of characters columnlimit:0# Note Align aligntrailingcomments:true# brackets and add spaces spaceaftercstylecast:true
Then select "File" in Xcode's "Edit", "CLang format", and let the penultimate line show "Disable format on Save" (the following is the actual situation, need not be formatted when the file is saved at any time).
Attach all available parameters of Clangformat document: http://clang.llvm.org/docs/ClangFormatStyleOptions.html
IOS Code Formatting Management