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)) // 5All lessons in this course
- SwiftFormat / SwiftLint basics
- Style guide, API design guidelines
- Documenting code (DocC intro)