AppCode inspections for your code perfection

AppCode helps you keep your code accurate and clean and does so as you type so you don’t need to interrupt your coding process. This is what the inspection mechanism is about. If you’re not familiar with this mechanism, you can read our tutorial that describes the essential principles. In this post we’d like to focus on some of the issues where AppCode’s code inspections can help you.
The full list of inspections includes over 100 items, but here we’ll point out a few of the most interesting and useful ones. Do not hesitate to go to Preferences | Inspections for the full list.

Hides class scope
When the codebase is big and complicated sometimes you may create a local variable or parameter with the name of an existing instance variable. This can produce problems if not done on purpose. The “Hides class scopes” inspection helps you to pay attention to such places:

AppCode will suggest solutions (Alt+Enter), like for example rename the parameter.

Unused code
AppCode helps you find unused code whether it is a class, an expression result, a declaration, a macro, a method or a property. All of these are detected automatically and the IDE suggests the “Safe delete” quick-fix.

Unavailable API
AppCode helps you comply with the deployment target API. In case you use some deprecated API or one that is not available for your target OS, the IDE shows you the inspection “Usage of the API unavailable for the deployment target”.

Key value coding
KVC is a powerful idea that allows you to access an object’s properties indirectly, using strings. It’s a convenient and straightforward approach but can be tricky if a mistake takes place in a field, method or property name and thus causes the exception in run-time. AppCode tracks these keypaths and checks they are defined.

And of course it suggests you a quick fix like for example to create the property with the given keypath:

Missing switch case
In case you have a wide-ranged enum you can miss some values while implementing a switch case operator over this enum type. Or you can possibly miss the default branch for the switch case over the integer type. This won’t be a problem with the “Missing switch case” inspection. AppCode tracks such places for you.

The quick fix automatically creates the missing branches (like default here).

Non-localized string
To ensure all strings are translated correctly, the inspection “Non-localized string” helps you find

and localize them with NSLocalizedString.

Simplifiable statement
After several refactorings and reviewings of the code some statements become clearly simple though you can miss it. AppCode will help you to make your code perfect in this sense. “Simplifiable statement“ inspection finds all the constant conditions, identical if branches and much more

and suggests you to simplify the code.

Fitting into receiver
‘Value may not fit into receiver’ inspection is very close to the previous one but in fact more general. If the receiver in the assignment narrows the value range it can cause errors. To stay protected from such issues one definitely should pay attention to the AppCode hint:

Redundant cast
Continuing with types AppCode checks all of them for you and suggests which type casts are redundant. Still to leave it or to remove is fully up to you but why not to know the scope?

Hiding non-virtual function
In the project with a huge inheritance tree one can simply forget or just miss some methods from the base class and implement a function in descendant with the same signature as in the ancestor. AppCode helps you here too! Inspection ‘Hiding non-virtual function’ tracks this situation

and suggests the quick fix like making the parent class function virtual:

And what’s your favorite inspection? Feel free to check out the full list in Preferences | Inspections.

This entry was posted in Tips'n'Tricks. Bookmark the permalink.

7 Responses to AppCode inspections for your code perfection

  1. Miki says:

    So… any news about new C++ IDE? :)

    • Anastasia Kazakova says:

      We are still working on it and will release it as we are ready. Follow the blog for the updates.

      • George Cook says:

        I don’t think miki is cross; I think he’s desperate to get his hands on these cool features!! where else can you get such productivity except for jetbrains?

  2. George Cook says:

    While I’m here, just want to say I use all of these constantly.

    I love you guys so much: You are the Gibson, Mercedes or dare I say, Apple of IDES.

    You guys rock, which is why I always evangelize your products.

    I always pop in here every few months to make sure you still know how much I appreciate your hard work on appcode.

    T H A N K S!!!

  3. User says:

    Will you guys fully multi-thread your inspection engine? I have 12 core / 24 hyperthreads available to use and it seems like inspection only uses one core. Almost everyone at least has 2 or 4 cores in iOS dev, so it significantly slows down usage of the app.

    Also builds don’t seem to take full advantage of all available cores, while xcode does. Same with it’s analyze function.

    • Anton Makeev says:

      Yes, inspections run simultaneously where possible, though there is room for optimization, of course, we’ll see what we can do

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">