I have a few questions about Swift documentation comments:
Is there a way to make a Related declarations section like some of the Apple documentation has? For e
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.