0Pricing
Swift Academy · Lesson

Documenting code (DocC intro)

Write DocC comments (/// and /** ... */), document parameters/returns, add examples, and generate static docs for SwiftPM packages.

Why DocC?

DocC turns well-placed comments into a browsable doc site.

  • Use /// or /** ... */
  • Describe what and show a tiny example
  • Document parameters and returns

Function docs

Place /// directly above the declaration. Use lists for Parameters and Returns.

/// Adds two integers and returns the sum.
/// - Parameters:
///   - a: First addend.
///   - b: Second addend.
/// - Returns: The sum of `a` and `b`.
/// - Remark: Pure function; no side effects.
func sum(_ a: Int, _ b: Int) -> Int { a + b }

print(sum(2, 3)) // 5

All lessons in this course

  1. SwiftFormat / SwiftLint basics
  2. Style guide, API design guidelines
  3. Documenting code (DocC intro)
← Back to Swift Academy