Spell check in Xcode

i.vikash
4 min readNov 6, 2021

--

How do we turn on spell check in Xcode ?

Being a developer when we write a code, we put more focus on logics and algorithms but not much on the spellings and grammars. But it is also an important part of our coding, especially when we show some message to the end users and generate documents from the comments.

Spell check help us to do find out the typo errors, and we get more time to focus on logic.

I have already written a post, how to generate documents in Xcode you can checkout from below link : https://medium.com/@i.vikas/how-to-create-rich-and-engaging-documents-like-apple-in-xcode-209bb91ea9f1

So let’s start:

1st question is what a spell check can identify ?

The answer is everything related to spelling and grammar in your source editor -

  • Variable name
  • Methods
  • Classes
  • Comments
  • String literals (including localization)

Now let’s take try to understand it with a sample code -

Before enabling “Spelling and Grammar”

In above image I have written some sample code with class, methods, variables and comment without enabling “Spelling and Grammar”. If we check carefully it has a lot of typo error and our eyes can only catch few of them.

Now let’s enable the “Spelling and Grammar” and see what happens -

After enabling “Spelling and Grammar”

In above image we can see that when we enable the spell check it detects all typo errors and highlighted it in red. Now we can resolve the error without spending much time.

How to enable spell check in xcode

Edit > Format > Spelling and Grammar > Check Spelling While Typing.

Once you enable it, all typo errors get highlighted in red in your project.

Along with this we have few other options as well -

Check Document Now:

It will show typo error one by one in the current file. For checking all the errors in current file you can repeat this command -

Edit > Format > Spelling and Grammar > Check Document Now.

or

(⌘;) command + semicolon

Show Spelling and Grammar:

It will open all the suggested changes. We can click any of them to replace.

Edit > Format > Spelling and Grammar > Show Spelling and Grammar.

or

(⌘:) command + colon

How do we fix the spell check problems

In Xcode we can fix it in two ways -

  1. From Spelling and Grammar window- which we have just discussed above.
  2. From Context Menu - when we “Right click” on the error, a context menu will appear with suggested replacement.

Here we can see that the suggested replacement is shown as “Company”. We can click on this to replace.

Till now we have discussed that how Spell Check helps us to quickly identify and fix the typo errors. On top of this sometimes we want to use some unique words which are not defined in the system dictionary, like app prefix, developer name company name etc. The Xcode starts showing errors for those words also.

So let’s understand how we can handle these unique words.

For this we have features like “Learn Spelling” and “Unlearn Spelling

Learn Spelling :

Using this we can add new words in the system dictionary for future usage. Once the word gets added in the dictionary, the Xcode will not show any typo error for those words.

New words can be added in two ways -

  1. From Context Menu : “Right click” on the word which we want to add in dictionary and select “Learn Spelling”

2. From Spelling and Grammar window: Open spelling and grammar window (Edit > Format > Spelling and Grammar > Show Spelling and Grammar) select learn.

Unlearn Spelling:

Xcode has no direct option to unlearn spelling so we have to unlearn the word from our system dictionary directly (mac in my case). This process may differ from system to system.

Open Library > Spelling > en (language file) and then remove word from this file.

PATH: /Users/USER_NAME/Library/Spelling

In above image we can see a new word “campany” have been added in our dictionary (as we did in our above example). We can remove it from here.

Conclusion :

Xcode spell check helps developers to find and fix typo errors across all the source code in editors without adding any external tools or library. It also saves the developer’s and reviewer’s time during testing.

Thank you for reading!

--

--

i.vikash

Tech enthusiast exploring software architecture, development, and innovation. Join me on my journey of tech discovery! 🚀 #TechExploration