0
0
Swiftprogramming~5 mins

Comments and documentation markup in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of comments in Swift code?
Comments explain the code to humans. They help others (and yourself) understand what the code does without affecting how the program runs.
Click to reveal answer
beginner
How do you write a single-line comment in Swift?
Use two slashes // before the comment text. Everything after // on that line is ignored by the compiler.
Click to reveal answer
beginner
How do you write a multi-line comment in Swift?
Start with /* and end with */. Everything between is treated as a comment, even if it spans many lines.
Click to reveal answer
intermediate
What is documentation markup in Swift and why is it useful?
Documentation markup uses special comment styles (like ///) to create structured notes. These notes can be shown in code editors to explain functions, parameters, and return values clearly.
Click to reveal answer
intermediate
Give an example of a documentation comment for a Swift function.
/// Adds two numbers and returns the result.
/// - Parameters:
///   - a: The first number.
///   - b: The second number.
/// - Returns: The sum of a and b.
Click to reveal answer
Which symbol starts a single-line comment in Swift?
A#
B//
C/*
D<!--
What does the following Swift comment style /// indicate?
AA compiler directive
BA single-line comment
CA multi-line comment start
DA documentation comment for code explanation
How do multi-line comments behave in Swift?
AThey start with <code>/*</code> and end with <code>*/</code>
BThey start with <code>//</code> and end with a blank line
CThey start with <code>///</code> and end with <code>///</code>
DThey start with <code>#</code> and end with <code>#</code>
Why should you use documentation comments in your Swift code?
ATo help others understand your code with clear explanations
BTo make the code run faster
CTo hide code from the compiler
DTo change the code's logic
Which of these is NOT a valid Swift comment style?
A/// This is a documentation comment
B/* This is a comment */
C<!-- This is a comment -->
D// This is a comment
Explain the difference between single-line, multi-line, and documentation comments in Swift.
Think about how each comment type looks and what it is used for.
You got /3 concepts.
    Write a documentation comment for a Swift function that multiplies two numbers and returns the result.
    Follow the Swift documentation comment format with clear sections.
    You got /4 concepts.