This answer was last revised for Swift 5.2 and Xcode 11.4.
You can use markup to write standard code documentation (using ///
or /** */
) and rich playground documentation (using //:
or /*: */
).
/// This function returns a welcoming string for a given `subject`.
///
/// ```
/// print(hello("World")) // Hello, World!
/// ```
///
/// - Warning: The returned string is not localized.
/// - Parameter subject: The subject to be welcomed.
/// - Returns: A hello string to the `subject`.
func hello(_ subject: String) -> String {
return "Hello, (subject)!"
}
As for documenting related symbols, there is a SeeAlso
markup tag but requires you to write an explicit URL to your related symbol's documentation page.
If you want to generate HTML documentation index for your project, I recommend checking out jazzy and swift-doc. They're both amazing open-source projects, and are even used by Apple itself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…