IOS Code Formatting Management

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.