{"id":225037,"date":"2022-02-15T14:26:00","date_gmt":"2022-02-15T13:26:00","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=objc&#038;p=225037"},"modified":"2022-08-09T16:42:51","modified_gmt":"2022-08-09T15:42:51","slug":"writing-code-documentation-in-appcode","status":"publish","type":"appcode","link":"https:\/\/blog.jetbrains.com\/fr\/appcode\/2022\/02\/writing-code-documentation-in-appcode","title":{"rendered":"Writing Code Documentation in AppCode"},"content":{"rendered":"<p>Code documentation can save you a lot of time and headaches. On the other hand, it also takes a lot of effort to write and maintain it. In this article, we will look at the AppCode features that can help you create detailed and well-structured code documentation and keep it updated after code refactorings.<\/p>\n<p>The features that we will describe here are available for Objective-C and Swift. Install <a href=\"https:\/\/www.jetbrains.com\/objc\/whatsnew\/\" target=\"_blank\" rel=\"noopener\">AppCode 2021.3<\/a> to get the full Swift documentation support.<\/p>\n<h1 id=\"documentation_comments\">Documentation comments<\/h1>\n<p>To add simple notes to your code, you can use line (<code>\u2318\/<\/code>) and block (<code>\u2325\u2318\/<\/code>) comments:<\/p>\n<p><img decoding=\"async\" alt=\"Line comment\" width=\"500\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/line_comments.png\"><\/p>\n<p>However, these comments are not supposed to be used for documentation purposes. This is how you would usually mark code that shouldn\u2019t compile:<\/p>\n<p><img decoding=\"async\" alt=\"Block comment\" width=\"500\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/block_comments.png\"><\/p>\n<p>To achieve consistent descriptions of classes, methods, and properties, you can use <em>documentation comments (doc comments)<\/em>. Doc comments have special syntax. In Swift, there are two possible ways to use them:<\/p>\n<p><img decoding=\"async\" alt=\"Documentation comments syntax\" width=\"500\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/doc_comments_syntax.png\"><\/p>\n<h1 id=\"generate_documentation_comments\">Generate documentation comments<\/h1>\n<p>In AppCode, you can generate doc comments quickly: just type<code> \/\/\/<\/code> or <code>\/**<\/code>, depending on the syntax you want to use, and press<code> <\/code><code>\u23ce<\/code>:<\/p>\n<p><img decoding=\"async\" alt=\"Generate documentation comments\" width=\"500\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/doc_comment_generate.gif\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/doc_comment_generate.png\"><\/p>\n<p>Doc comments should precede the declaration of a code element that you want to describe. The content of the comment becomes the documentation that pops up on mouse hover or on pressing <code>F1<\/code>:<\/p>\n<p><img decoding=\"async\" alt=\"Code documentation in a popup\" width=\"500\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/documentation_popup.png\"><\/p>\n<p>When adding a doc comment for a method or function, AppCode generates documentation stubs containing all available parameters and the <code>Returns<\/code> and <code>Throws<\/code> keywords if the function\/method throws or returns anything:<\/p>\n<p><img decoding=\"async\" alt=\"Generate documentation for a method\" width=\"600\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/generate_doc_for_method.gif\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/generate_doc_for_method.png\"><\/p>\n<h1 id=\"format_documentation_comments\">Format documentation comments<\/h1>\n<p>Text inside the comments can be formatted using the standard <a href=\"https:\/\/www.markdownguide.org\/basic-syntax\/\" target=\"_blank\" rel=\"noopener\">Markdown syntax<\/a>. You can add links, highlight text in bold and italics, add headers, and more:<\/p>\n<p><img decoding=\"async\" alt=\"Markdown formatting in documentation comments\" width=\"600\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/markdown_formatting.png\"><\/p>\n<p>In addition to the standard markup, you can use documentation-specific keywords, such as <code>Warning<\/code>, <code>Note<\/code>, <code>Version<\/code>, <code>See Also<\/code>, and others. Just type <code>-<\/code>, and AppCode will show you all the possible options:<\/p>\n<p><img decoding=\"async\" alt=\"Documentation key words\" width=\"600\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/doc_keywords.png\"><\/p>\n<p>You can also change the style of the documentation comments. Go to <strong>Preferences | Editor | Color Schemes | Swift<\/strong> and adjust colors and effects for tags, values, and text under the corresponding nodes:<\/p>\n<p><img decoding=\"async\" alt=\"Formatting documentation comments\" width=\"600\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/doc_comments_colors.png\"><\/p>\n<h1 id=\"refactorings_in_code_documentation\">Refactorings in code documentation<\/h1>\n<p>AppCode helps you keep code documentation up to date after changing a method\/function signature. For example, when you are renaming parameters of a method using the <strong>Rename<\/strong> refactoring (<code>\u21e7F6<\/code>), the parameter names change in the comments as well:<\/p>\n<p><img decoding=\"async\" alt=\"Rename parameters\" width=\"600\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/rename_parameters.gif\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/rename_parameters.png\"><\/p>\n<p>Similarly, the <strong>Change Signature<\/strong> refactoring (<code>\u2318F6<\/code>) affects the comments when you add or remove parameters or change their order:<\/p>\n<p><img decoding=\"async\" alt=\"Change signature\" width=\"600\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/change_signature.gif\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/change_signature.png\"><\/p>\n<h1 id=\"rendered_view\">Rendered view<\/h1>\n<p>You can view doc comments in an easier-to-read format. Just click the icon in the gutter to switch between rendered view and edit mode:<\/p>\n<p><img decoding=\"async\" alt=\"Rendered view\" width=\"600\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/rendered_mode.gif\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/rendered_mode.png\"><\/p>\n<p>All doc comments in read-only library files are displayed in rendered format by default. You can disable <a href=\"https:\/\/www.jetbrains.com\/help\/objc\/reader-mode.html\" target=\"_blank\" rel=\"noopener\">Reader Mode<\/a> in the top right corner of the editor to show the comments as code:<\/p>\n<p><img decoding=\"async\" alt=\"Reader mode\" width=\"600\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/02\/reader_mode.png\"><\/p>\n<h1 id=\"summary\">Summary<\/h1>\n<p>We hope that AppCode\u2019s code generation, auto-completion, and refactoring features that we described here will encourage you to create detailed and consistent code documentation.<\/p>\n<p>For more information on code documentation support, refer to our <a href=\"https:\/\/www.jetbrains.com\/help\/objc\/creating-and-viewing-doxygen-documentation.html\" target=\"_blank\" rel=\"noopener\">web help<\/a>.<\/p>\n","protected":false},"author":1139,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","categories":[4244,601],"tags":[6935,6936,1445,6937],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/appcode\/225037"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/appcode"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/types\/appcode"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/users\/1139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/comments?post=225037"}],"version-history":[{"count":4,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/appcode\/225037\/revisions"}],"predecessor-version":[{"id":228269,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/appcode\/225037\/revisions\/228269"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media?parent=225037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/categories?post=225037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/tags?post=225037"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/cross-post-tag?post=225037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}