如何在Swift中为枚举关联值添加文档

Wet*_*ish 15 xcode swift

有没有办法在Swift 3中为枚举的关联值添加描述?我希望它们出现在符号文档弹出窗口(选项+单击)中,就像它们对Xcode 8中的函数参数一样.

这是我的枚举:

enum Result {
    /**
    Request succeeded.

    - Parameters:
      - something: Some description.
      - otherThing: Other description.
    */
    case Success(something: Int, otherThing: Int)

    /**
    Request failed.

    - Parameter error: Error.
    */
    case Error(error: Error)
}
Run Code Online (Sandbox Code Playgroud)

我尝试过使用- Parameters:,但它在枚举中不起作用.

jqg*_*imo 18

像这样做:

/// Enum Description
enum Enum {
    /// enum1 Description
    /// - value1: value1 Description
    /// - value2: value2 Description
    case enum1(value1: Int, value2: String)

    /// enum2 Description
    case enum2
}
Run Code Online (Sandbox Code Playgroud)

显示结果: 在此输入图像描述


kha*_*mur 18

看起来- Parameter效果很好。

enum Vegetable {
    
    /// Potato.
    /// - Parameter variety: Variety of potato.
    /// - Parameter mass: Mass of a potato in kilograms.
    case potato(variety: String, mass: Float)
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 这应该是公认的答案,很好的发现! (3认同)