I am using Xcode 12.3 and I need to change the default shortcut for the 'Clean Build' action.
By default, Xcode binds this to Command
+ Shift
+ K
(as also seen in the Product menu within the IDE).
Xcode provides an option to change key bindings from the "Key Bindings" tab in Xcode Preferences as shown below.
For other shortcuts, we can double click on the shortcut text, and a Text Field will appear to change the shortcut. Simply enter your new shortcut and it will be changed.
However, when I double click on the shortcut for the "Clean" key binding, it does not allow me to change the shortcut. Almost as if it is "locked".
Can anyone please help me to change this shortcut?
It is really inconvenient since the shortcut for the Object Library is Command
+ Shift
+ L
. I accidentally end up cleaning my project and having to wait a long time for the next build to complete. Not fun when a clean build takes around 10 mins to compile :(
Thanks to @LinusGeffarth's comment, I was able to get this resolved. I've organized the answer to my question into 3 parts.
Because since Xcode 10, the "Clean" and "Clean Build Folder" does the same thing. Xcode still maintains the shortcut for the "Clean" option. It is not present in any of the menus, but pressing the shortcut invokes the "Clean Build Folder" action. Reference
The new build system uses the “clean build folder” behavior. The legacy “clean” behavior is not supported.
For those wondering whether there was a difference in the two, there is a great StackOverflow Answer here.
If you select Clean from the Product menu, XCode will delete the files inside every folder in the Build folder, if you select Clean Build Folder it will delete the entire Build folder.
Here are the steps I followed.
Control
+ Shift
+ Command
+ B
) shorcut.Add
.This overrides the default Clean Build shortcut on Xcode. Pressing Command
+ Shift
+ K
does not clean build anymore.
I am left with a small side-effect in the Product menu of Xcode. There are now two Clean Build Folder options in Xcode (as shown below).
However the issue is resolved. The "Clean" shortcut is disabled. It does not specifically bother me that there's another option, but it does make my answer a bit incomplete.
As mentioned in Part 1, the "Clean" option is not actually present in the Xcode Product menu. So overriding the "Clean" shortcut will not do anything.
I checked whether the key binding was removed after overriding the "Clean" option but it wasn't. Pressing Cmd + Shift + K still cleaned the build folder.
However, overriding the "Clean Build Folder" option also overrides the action for the "Clean" shortcut (I am not sure why).