How to use Swift documentation comments

后端 未结 5 1237
你的背包
你的背包 2021-01-30 01:10

I have a few questions about Swift documentation comments:

  1. Is there a way to make a Related declarations section like some of the Apple documentation has? For e

5条回答
  •  失恋的感觉
    2021-01-30 01:37

    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.

提交回复
热议问题