AppCode 2023.1 Help

File templates

File templates are specifications of the default contents for new files that you create. Depending on the type of file you are creating, templates provide initial code and formatting expected in all files of that type (according to industry or language standards, your corporate policy, or for other reasons).

AppCode provides predefined templates for all supported file types suggested when you create a new file.

Manage and configure file templates

  • Press Ctrl+Alt+S to open the IDE settings and select Editor | File and Code Templates.

For more information, see File and Code Templates.

By default, the list of templates contains only predefined templates provided by AppCode. Some of them are internal, which means they cannot be deleted or renamed. AppCode shows the names of internal templates in bold. The names of templates that you modified, as well as custom templates that you created manually, are shown in blue.

The following procedures describe how to create file templates. Similar procedures can be used for creating include templates.

Create a new file template

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | File and Code Templates.

  2. Using the Scheme list, select the scope to which the file template apply:

    • Default: configure file templates for the entire application. These templates are available in all projects that you open with the current IDE instance. Use them as your personal templates that you prefer regardless of the specific project. AppCode stores global templates in the IDE configuration directory under fileTemplates.

    • Project: configure file templates specific for the current project. These templates are available to everyone who works on this project. AppCode stores them in the project folder under .idea/fileTemplates.

  3. On the Files tab, click the Create Template button and specify the template name, file extension, name of the resulting file, and body of the template.

  4. Apply the changes and close the dialog.

Copy an existing file template

  1. Press Ctrl+Alt+S to open the IDE settings and select Editor | File and Code Templates.

  2. On the Files tab, click the Copy Template button and modify the name, file extension, and body of the template as necessary.

  3. Apply the changes and close the dialog.

Save a file as a template

  1. Open a file in the editor.

  2. From the main menu, select File | Save File as Template.

  3. In the Save File as Template dialog, specify the new template name and edit the body, if necessary.

  4. Apply the changes and close the dialog.


File templates use the Velocity Template Language (VTL), which includes the following constructs:

  • Plain text rendered as is.

  • Variables that are replaced by their values. For example, ${NAME} inserts the name provided by the user when adding the file.

  • Various directives, including #parse, #set, #if, and others.

Start typing $ or # to see completion suggestions for available variables and directives.

For more information, see the VTL reference guide.

The following example shows the default template for creating an Objective-C class in AppCode:

#parse("C File Header.h") #import "${HEADER_FILENAME}" @implementation ${NAME} #if ($PUT_IVARS_TO_IMPLEMENTATION == "true"){ } #end @end

This template is organized as follows:

  • The #parse directive is used to insert the contents of the C File Header.h template.

  • The #import directive is used to insert the link to the header file.

  • The template then adds an implementation for a class with the name passed as the ${NAME} value (name of the new file). $PUT_IVARS_TO_IMPLEMENTATION defines, if instance variables should be put inside the class implementation. You can change the value of this option using the Put ivars to implementation if possible checkbox (AppCode | Preferences | Editor | Code Style| C/C++/Objective-C). If the value is true, curly braces will be added after the class name.

When you create a new Objective-C class based on the template, a file with contents similar to the following is generated:

// // Created by John Smith on 2019-07-01. // Copyright (c) 2019 JetBrains. All rights reserved. // #import "NewClass.h" @implementation NewClass { } @end

The corresponding header file is created at the same time.

Last modified: 02 February 2023