← frouo.com

Xcode 12.3

How to avoid the "Non-breaking space used instead of regular expression" warning in Xcode

Why this warning?

Non-breaking space is produced by pressing ⌥ optionspace. Which happens to me all the time when typing such a code line items.map { ... } because I tend to hold prematurely or release too late the ⌥ option key needed to print the { or } symbols (azerty).

map⌥ option (holding)space(

Chosen solution

Use a snippet!

Create an empty closure snippet and use ⌘ cmd⇧ shiftL to insert the snippet. It even ended up speeding up my workflow 🎉

snippet library


snippet usage

How to create this snippet

  1. Type your snippet in Xcode, here items.map { <#code#> }
  2. Select the part of the snippet, here space{ <#code#> }
  3. Xcode Menu > Editor > Create Code Snippet
  4. Enter a title
  5. Click Done

create snippet

An azerty keyboard thing

As I said, I guess this ennoying thing should mostly concern AZERTY keyboards because on these keyboards, you have to hold ⌥ option to print { or }.

First try with editing IDETextKeyBindingSet.plist file

I did try this stackoverflow answer from klanomath 🙏🏻.

It's kind of work. Indeed I no longer have the warning but for the reason that ⌥ optionspace no longer works at all: no more space neither normal nor non-breaking.

Which was very bordering on my typing speed.

Plus I would probably have to redo the modification with every new Xcode version.

Also tried with no luck

  1. iTerm2 stackoverflow answer but it's only working inside the iTerm2 editor
  2. Modifying ~/Library/KeyBindings/DefaultKeyBinding.dict stackoverflow answer but I don't want to touch that file indeed...

Now I use the snippet.

Please reach me if you find a better solution 👋

Thank you

Hope it helps. Please drop a ❤️ on my Twitter post to show your support 🙏.

The source code for this blog is available on GitHub.