Thanks to @LinusGeffarth's comment, I was able to get this resolved. I've organized the answer to my question into 3 parts.
1. Why it is not possible to change the "Clean" key binding from Xcode?
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.
2. How can I change the "Clean" shortcut?
Here are the steps I followed.
- Open System Preferences.
- Navigate to, Keyboard → Shortcuts → App Shortcuts
- Click the + button.
- Select "Xcode" as the Application.
- Enter "Clean Build Folder" as the Menu Title.
- Click on the Keyboard Shortcut TextField and enter a preferred shortcut.
- I chose the, ⌃⇧⌘B (
Control
+ Shift
+ Command
+ B
) shorcut.
- Click
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.
3. Why didn't you use "Clean" as the menu title in Part 2?
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).