[xcode] How to format code in Xcode?

I wonder how can I format my code to align it neatly? Does it have a feature similar to Eclipse's ctrlshiftf?

This question is related to xcode format keyboard-shortcuts code-formatting

The answer is


Select first the text you want to format and then press Ctrl+I.

Use Cmd+A first if you wish to format all text in the selected file.

Note: this procedure only re-indents the lines, it does not do any advanced formatting.


In XCode 12 beta:

The new key binding to re-indent is control+I.


Key combination to format all text on open file:

Cmd ? A + Ctrl I


I would suggest taking a look JetBrains AppCode IDE. It has a Reformat Code command. I have come from a C# background and used Visual Studio with Jetbrains Resharper plugin, so learning AppCode has been a pleasure because many of the features in Resharper also exist in AppCode!

Theres too many features to list here but could well be worth checking out


  1. Select the block of code that you want indented.

  2. Right-click (or, on Mac, Ctrl-click).

  3. Structure → Re-indent


Examples related to xcode

Undefined Symbols error when integrating Apptentive iOS SDK via Cocoapods Xcode 12, building for iOS Simulator, but linking in object file built for iOS, for architecture arm64 iPhone is not available. Please reconnect the device Make a VStack fill the width of the screen in SwiftUI error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65 The iOS Simulator deployment targets is set to 7.0, but the range of supported deployment target version for this platform is 8.0 to 12.1 Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Xcode 10: A valid provisioning profile for this executable was not found Xcode 10, Command CodeSign failed with a nonzero exit code

Examples related to format

Brackets.io: Is there a way to auto indent / format <html> Oracle SQL - DATE greater than statement What does this format means T00:00:00.000Z? How to format date in angularjs How do I change data-type of pandas data frame to string with a defined format? How to pad a string to a fixed length with spaces in Python? How to format current time using a yyyyMMddHHmmss format? java.util.Date format SSSSSS: if not microseconds what are the last 3 digits? Formatting a double to two decimal places How enable auto-format code for Intellij IDEA?

Examples related to keyboard-shortcuts

Collapse all methods in Visual Studio Code Is there a keyboard shortcut (hotkey) to open Terminal in macOS? Jupyter/IPython Notebooks: Shortcut for "run all"? Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse? How do I duplicate a line or selection within Visual Studio Code? How do I search for files in Visual Studio Code? OS X Terminal shortcut: Jump to beginning/end of line window.close() doesn't work - Scripts may close only the windows that were opened by it Comment shortcut Android Studio Column/Vertical selection with Keyboard in SublimeText 3

Examples related to code-formatting

How do you format code on save in VS Code How do you format code in Visual Studio Code (VSCode) JavaScript Chart.js - Custom data formatting to display on tooltip Is there a command for formatting HTML in the Atom editor? How to auto-indent code in the Atom editor? Code formatting shortcuts in Android Studio for Operation Systems How to auto-format code in Eclipse? How to format code in Xcode? What is the proper way to format a multi-line dict in Python? How do I format XML in Notepad++?