如何在 Swift 中添加文档以枚举关联值 [英] How to add documentation to enum associated values in Swift

查看:48
本文介绍了如何在 Swift 中添加文档以枚举关联值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to add descriptions to associated values of enums in Swift 3? I want them to show up in the symbol documentation popup (option+click), like they do for function parameters in 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)
}

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

I tried using - Parameters:, but it doesn't work in enums.

推荐答案

这样做:

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

    /// enum2 Description
    case enum2
}

<小时>

显示结果:


Show result:

这篇关于如何在 Swift 中添加文档以枚举关联值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆