This is the 8th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021


The introduction

As developers, when we write code, we focus more on logic and algorithms than spelling and syntax. But it’s also an important part of our coding, especially when we’re generating documentation from annotations.

Spell checking helps us spot spelling errors and gives us more time to focus on code logic.


What does spell check recognize

The answer is all the Spelling and Grammer stuff in the code

  • The variable name
  • methods
  • class
  • annotation
  • String literals (including localization)

Let’s start with some code:

In the code above, classes, methods, variables, and annotations are included, but Spelling and Grammer are not enabled. At first glance, there seems to be nothing wrong, but if we examine it carefully, we will find many spelling mistakes.

Now let’s turn on Spelling and Grammer and see what happens –

In the code above we can see that when spell checking is enabled, it detects all spelling errors and highlights them in red. Now we don’t have to look for mistakes, we can just fix them.


How to open

Edit > Format > Spelling and Grammar

You can see that there are three options available. Let’s look at them in turn:

Check Spelling While Typing

When enabled, all input errors in the project are highlighted in red at once, as in the example above.

In addition, with this option enabled, you can also select the word you want to change and right click to see the word suggested by Xcode in the menu.

Check Document Now

It displays input errors one by one in the current file. To Check for all errors in the current file, repeat the command Edit > Format > Spelling and Grammar > Check Document Now

Or use the shortcut keys command and semicolon (;) The combination of

Show Spelling and Grammar

It opens all suggested changes. We can click on any of them to replace. Use the command Edit > Format > Spelling and Grammar > Show Spelling and Grammar

Or use a combination of command and the colon (:)


Learn Spelling and Ignore Spelling

Sometimes we need to use unique terms that are not defined in the system dictionary, such as application prefixes, developer names, company names, etc. Xcode also checks for errors in these words.

So we use “Learn Spelling” or “Ignore Spelling” to deal with these particular words.

Through the menu

Right-click on the word you want to work with

With command + :


conclusion

Explore the three options of Edit > Format > Spelling and Grammar