Does Swift have documentation generation support?

前端 未结 12 1393
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 00:15

Many languages support documentation comments to allow a generator (like javadoc or doxygen) to generate code documentation by parsing that sam

相关标签:
12条回答
  • 2020-11-28 00:31

    Yes. Base common (I made snippets for it with Obj-C equivalent)

    Objective-C:

    /**
     @brief <#Short description - what it is doing#>
    
     @discussion <#Description#>
    
     @param  <#paramName#> <#Description#>.
    
     @return <#dataType#> <#Description#>.
     */
    

    Swift

    /**
    <#Short inline description - what it is doing#>
    
    <#Description#>
    
    :param:  <#paramName#> <#Description#>.
    
    :returns: <#dataType#> <#Description#>.
    */
    
    0 讨论(0)
  • 2020-11-28 00:33

    Here are some things that work for documenting swift code in Xcode 6. It is very buggy and sensitive to colons, but it's better than nothing:

    class Foo {
    
        /// This method does things.
        /// Here are the steps you should follow to use this method
        ///
        /// 1. Prepare your thing
        /// 2. Tell all your friends about the thing.
        /// 3. Call this method to do the thing.
        ///
        /// Here are some bullet points to remember
        ///
        /// * Do it right
        /// * Do it now
        /// * Don't run with scissors (unless it's tuesday)
        ///
        /// :param: name The name of the thing you want to do
        /// :returns: a message telling you we did the thing
        func doThing(name : String) -> String {
            return "Did the \(name) thing";
        }
    }
    

    The above is rendered in Quick Help as you would expect with formatted numeric lists, bullet points, parameter and return value documentation.

    None of this is documented - file a Radar to help them along.

    0 讨论(0)
  • 2020-11-28 00:35

    Swift includes "///" comment handling (although probably not everything yet).

    Write something like:

    /// Hey!
    func bof(a: Int) {
    
    }
    

    Then option-click on the func name and voilà :)

    0 讨论(0)
  • 2020-11-28 00:37

    Jazzy can help to generate beautiful apple styled documentation. Here is a sample app with details on how to use and configure quickly.

    https://github.com/SumitKr88/SwiftDocumentationUsingJazzy

    0 讨论(0)
  • 2020-11-28 00:38

    As of Xcode 5.0, Doxygen and HeaderDoc structured comments are supported.

    Source

    0 讨论(0)
  • 2020-11-28 00:39

    Maybe it's a good idea to have an eye on AppleDoc or Apple's own HeaderDoc which isn't recognized very much. I can still find some HeaderDoc hints in 10.9 Mavericks terminal (headerdoc2html)

    I recommend to read the latest "What's New In Xcode"* (not sure if it's still under NDA) *The link points to the Xcode 5.1 version wich contains infos about HeaderDoc too.

    0 讨论(0)
提交回复
热议问题