I upgraded to mac os big sur and XCode 12.3. Earlier I was using XCodeClangFormat extension to format my C++ files. But now this extension is not getting recognized. When I open the extension I don’t see it in XCode in the Editor menu. I have already checked that the XCodeClangFormat extension is enabled in the System Preferences -> Extensions option for XCode Editor.
Anyone else facing this issue? Can you please suggest a solution for it. Thanks for your help
3
Answers
I have Xcode 12.4 and the source code formatter appears to be a priced product. If you click Xcode->Xcode Extensions, it takes you to App Store. There you will find Xformat priced at INR 269. Frankly, I didn’t attempt to use this. My favorite is astyle since my Linux days dating back to more than two decades.
Same here. The extension no longer seems to run. But it is not that bad at all. Since a while ago, I started using a script that would reformat my entire project before I commit.
<Edit>
I just need to have Homebrew installed, so I can download clang-format by
brew install clang-format
(Ref: https://formulae.brew.sh/formula/clang-format)</Edit>
It runs on double-click and I also integrated it to my git commit/pull/push script.
<Better Script>:
<Old Script>:
In the folder where you run this script, you must place the style-file with name ‘.clang-format’. Its content should be familiar to you.
If you use a predefined coding style, have a look at clang-format’s help
clang-format --help
and there look for ‘–style=’ description.Another way to use clang-format is by using automator. (Credits to the original author https://www.jianshu.com/p/1385ab726fc1)
Now you should be able to select the code and right click for Services -> clang-format (or the name you saved for the quick action)
You can also add shortcuts for the quick action in Keyboard Preferences.
Hope this helps! 😀 I just love this approach.