AppCode 2018.3 Help

Optimizing Imports

In this section:

Introduction

Sooner or later, some of the imported classes or functions become redundant to the code.

Typically, you have to stop what you are doing, scroll to the head of the file, find the unused imports, and remove them. It is rather easy to forget to remove imports when you remove usages.

AppCode provides the Optimize Imports feature, which enables you, whenever it is convenient, to remove unused imports from your current file, or from all files in the current directory at once. This helps you avoid unused, excessive and duplicating imports in your project.

One can remove unused import statements in the entire project or in the current file only.

Optimize imports in the project

  1. Place the caret at the Project tool window and do one of the following:

    • On the main menu, choose Code | Optimize Imports.

    • Press ⌃⌥O.

    The Optimize Imports dialog box opens.

  2. If your project is under version control, the option Only VCS changed files is enabled. Select or clear this option as required.

  3. Click Run.

One way of dealing with unused import is to use the quick-fix that appears when you set the caret at the highlighted unused import or include. However, you can optimize imports in a larger scope as described below.

Optimize imports in the current file

  1. On the main menu, choose Code | Optimize Imports.

  2. Press ⌃⌥O.

  3. Place the caret at the import statements, click icons actions intentionBulb svg, and choose Remove unused import.

  4. Open the Reformat File Dialog (⌥⇧⌘L) and select the Optimize imports checkbox.

Last modified: 28 March 2019

See Also