Add comment markers in your Swift code to mark text as prose.
Playground pages almost always need prose to introduce the concepts you’re teaching on the page. You use a special kind of Swift comment to mark single lines or blocks of text as prose. When a playground page’s
main file is displayed in Swift Playgrounds, comments marked as prose are displayed using a proportional font.
Add Single-Line Prose
To add short sections of prose to a page, write a single-line Swift comment that starts with a colon (
Comments without the colon are treated as normal Swift comments and are displayed in a monospace font. Text that’s outside of any sort of comment is treated as Swift code and runs when you tap Run My Code.
You can use markup in prose to add semantic treatments like emphasis and code voice. For information on supported markup, see Markup Formatting Reference.
Add Multiline Prose
Use multiline Swift comments for longer passages. You indicate that a multiline comment is prose by adding a colon immediately after the comment’s starting delimiter (
You don’t need to use a special delimiter to close the comment; use the regular comment closing syntax (
*/) to finish a multiline prose block.
Reference Localized Prose
Localize the content on a page by using the special comment syntax:
). The identifier key must correspond to an entry in the playground page’s
Prose file for each localization folder in the PrivateResources folder.
In the following example, the
Explanation key refers to localized prose in a page’s
Prose file, in the en.lproj folder under PrivateResources.
Strings files (localization files with names ending in
.strings) contain multiple key-value pairs, where the key is a phrase you use to identify a block of localized prose, and the value is the localized prose.
The example below shows an English localization of
The rendered playground page shows the text “Use loops to repeat an action multiple times until a condition is met.” If you provide multiple localizations of your playground book, the text displayed is matched to the locale chosen on the learner’s iPad.
Strings files are a common format used for several kinds of localization and internationalization tasks. For more information about formatting strings files, see String Resources and Internationalization and Localization Guide.