Install the clang – format

brew install clang-format

Check whether the installation is successful

clang-format --version

Recommended Parameter Settings

# tools (need to add a signature to use https://github.com/mapbox/XcodeClangFormat # function name, detailed address English http://clang.llvm.org/docs/ClangFormatStyleOptions.html # function name, detailed address Chinese https://www.cnblogs.com/PaulpauL/p/5929753.html # BasedOnStyle: LLVM # Align comment AlignTrailingComments: true # Pointer and reference alignment PointerAlignment: Right # Number of columns used for indentation IndentWidth: 4 # switch case IndentCaseLabels: true # OC ObjCSpaceAfterProperty True # OC, add Spaces before and after the Protocol ObjCSpaceBeforeProtocolList: true # single-line comments on the number of Spaces before SpacesBeforeTrailingComments: 1 # continuous empty lines retain a few lines of MaxEmptyLinesToKeep: 1 # retain block inside empty line KeepEmptyLinesAtTheStartOfBlocks: ColumnLimit: 0 # [] add space to SpacesInSquareBrackets: false # () add space to SpacesInParentheses: False # container classes before adding Spaces SpacesInContainerLiterals: true # add Spaces SpaceBeforeAssignmentOperators before the assignment operator: SpaceInEmptyParentheses: false # Insert space between <> SpacesInAngles: false # Align operator AlignOperands: #AlignAfterOpenBracket: Align #ContinuationIndentWidth: # = 0 # assignment alignment AlignConsecutiveAssignments: false statement parameters alignment AlignConsecutiveDeclarations: False position BreakBeforeBinaryOperators # operator: None # allows short functions in the same line # AllowShortFunctionsOnASingleLine: None # allows the case on the same line AllowShortCaseLabelsOnASingleLine: false # allows the if on the same line AllowShortIfStatementsOnASingleLine: False # allows while on the same line AllowShortLoopsOnASingleLine: false # allow put simple blocks in the same line AllowShortBlocksOnASingleLine: False # indentation function name IndentWrappedFunctionNames: false # parameter If false or are on the same line, or each have a line of BinPackParameters: False # Arguments if false are either on the same line, or on each line BinPackArguments: false # Braces newline BreakBeforeBraces: Custom BraceWrapping: AfterClass: true # AfterControlStatement: false # AfterEnum: false # AfterFunction: AfterNamespace: false # struct: false # union AfterUnion: False # catch previous BeforeCatch: falseCopy the code

Adding automated Services

Select Quick operation

Drag the shell to the right

Add content and check, save exit, give a name

export PATH=/usr/local/bin:$PATH
clang-format
Copy the code

End, open Xcode to use, right-click the code to view the script created in the previous step

You can also set shortcut keys system preference -> keyboard -> Shortcut keys -> APP shortcut keys -> Select Xcode(I prefer to save when formatting)