Documentation Archive

Developer

Markup Formatting Reference

On This Page

Code Block

Display the text as a block of code.

Works with:

  • ✓ Playgrounds

  • ✓ Symbol documentation

Syntax

Start each line of a code block indented at least four spaces or one tab from the indent level for the current delimiter. For information on indent level, see Quick Help Sections. There are empty lines above and below the code block.

  •     
  •         code line
  •         …
  •     

Alternate syntax for symbol documentation

Enter four backquotes (`) on a line above and below the lines for the code block. The four backquotes start at the indent level for the current delimiter. For information on indent level, see Quick Help Sections.

  • ````
  • code line
  • ````

Playground Example

Lines 3-5 in the markup below result in the code block shown in the screenshot.

  1. /*:
  2.  A loop to print each character on a seperate line
  3.     for character in "Aesop" {
  4.         println(character)
  5.     }
  6. */
image: ../Art/MFR_code_block_eg_2x.png

Quick Help Example

Lines 5-7 in each of the comment blocks below result in the code block shown in screenshot.

  1. /**
  2.  An example of using a *code block*
  3.  A loop to print each character on a seperate line
  4.     for character in "Aesop" {
  5.         print(character)}
  6.     }
  7. */

Alternate syntax

  1. /**
  2.  An example of using a *code block*
  3.  A loop to print each character on a seperate line
  4.  ````
  5.  for character in "Aesop" {
  6.   print(character)}
  7.  }
  8.  ````
  9. */
image: ../Art/MFR_symbol_code_block_2x.png