With the release of Xcode 16 apple added support for EditorConfig:
Added support for EditorConfig. The editor now respects indentation settings given in .editorconfig files. Xcode supports the following settings: indent_style, tab_width, indent_size, end_of_line, insert_final_newline, max_line_length, and trim_trailing_whitespace. See https://editorconfig.org for more information. Settings from .editorconfig files normally take precedence over settings given in the “Text Editing” section of View > Inspectors > File for a file or group. This can be disabled by unchecking the “Prefer Settings from EditorConfig” checkbox on the Indentation tab of Xcode > Settings > Text Editing. (20796230)
In my project I create a new .editorconfig file under root directory:
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
[*.swift]
indent_style = space
indent_size = 4
[*.{h, m, mm}]
indent_style = space
indent_size = 4
[*.metal]
indent_style = space
indent_size = 4
However, when I try to re-indent, it's not working
Turns out it's a known issue:
Changes to .editorconfig are not reflected immediately in open files. (120389049)
Workaround: Quit and restart Xcode.