To display and edit files correctly, AppCode needs to know which encoding to use. In general, source code files are mostly in UTF-8. This is the recommended encoding unless you have some other requirements.
To determine the encoding of a file, AppCode uses the following steps:
If the byte order mark (BOM) is present, AppCode will use the corresponding Unicode encoding regardless of all other settings. For more information, see Byte order mark.
If the file declares the encoding explicitly, AppCode will use the specified encoding. For example, this can apply to XML or HTML files. The explicit declaration also overrides all other settings, but you can change it in the editor.
If there is no BOM and no explicit encoding declaration in the file, AppCode will use the encoding configured for the file or directory in the file encoding settings. If encoding is not configured for the file or directory, AppCode will use the encoding of the parent directory. If the parent directory encoding is also not configured, AppCode will fall back to the Project Encoding, and if there is no project, to Global Encoding.
Change the encoding used to view a file
If AppCode displays characters in a file incorrectly, it probably couldn't detect the file encoding. In this case, you need to specify the correct encoding to use for viewing and editing this file.
With the file open in the editor, either select File Encoding widget on the status bar, and select the correct encoding of the file.from the main menu or click the
Encodings marked with or might change the file contents. In this case, AppCode opens a dialog where you can choose what to do with the file:
Reload: load the file in the editor from disk and apply encoding changes to the editor only. You will see the content changes related to the chosen encoding, but the actual file will not change.
Convert: overwrite the file with the chosen encoding.
This will add an association for the file to the file encoding settings. AppCode will use the specified encoding to view and edit this file.
Configure file encoding settings
In the Preferences dialog ⌃⌥S, select .
AppCode uses these settings to view and edit files for which it was not able to detect the encoding and also uses the specified encodings for new files.
Select the encoding to use when other encoding options don't apply.
For example, AppCode will use this encoding for files that are not part of any project or when you check out sources from a version control system.
|Project Encoding||Select the encoding to use for files that are not listed in the table.|
|Path||Specify the path to the files or directories for which you want to configure the encoding.|
Select the encoding to use for the specified files and directories.
If this selector is disabled, the file probably has a BOM or declares the encoding explicitly. In this case, you can't configure the encoding to use for this file.
The encoding selected for a directory applies to all files and subdirectories within it.
|Default encoding for properties files|
Select the encoding for properties files in your project.
|Transparent native-to-ascii conversion|
Show national characters (those not defined in ISO 8859-1) in place of the corresponding escape sequences.
|Create UTF-8 files|
Select how AppCode should create UTF-8 files:
By default, AppCode creates UTF-8 files without the BOM because some software is not compatible with the BOM, and it may be a problem when interpreting scripts. However, in some cases, you may want to have the BOM in your UTF-8 files.
Select console output encoding
By default, AppCode uses the system encoding to view console output.
In the Preferences dialog ⌃⌥S, select .
Select the default encoding from the Default Encoding list.
Click OK to apply the changes.
Different types of files use different ways to define encoding. AppCode recognizes encoding of files based on their contents.
Encoding has influence on the way AppCode reads or writes files. If a file has been modified but not yet saved, any changes in encoding affect file writing; if a file has not been modified, then reading is affected. AppCode suggests specific ways to change encoding of a file according to its type, using File Encodings Settings page, the Status bar, or the editor.
|Encoding||Can be changed in|
|File encoding is specified within the file, for example, in XML.||If a file contains explicit encoding declaration, you can change it in the Editor. In this case AppCode provides code completion.|
|File encoding is defined by BOM||In this case, you can't change encoding with which AppCode reads the file, but it is still possible to change encoding for writing such file.|
|UTF characters are detected in the file contents.||AppCode provides an option that automatically changes file encoding to UTF, if the file contents can be reasonably interpreted as UTF. |
This option only works for reading; a file can be saved with any encoding.
|Encoding cannot be found out from the file contents.||In this case, the default encoding is the one defined by the IDE encoding in the File Encodings page of the Settings dialog. You can change it for multiple files and directories, or for a single file.|