【问题标题】:Is there a Xcode shortcut to type all the enum cases in a switch?是否有 Xcode 快捷方式可以在 switch 中键入所有枚举案例?
【发布时间】:2021-09-19 16:01:52
【问题描述】:

假设我有这个枚举:

enum Test {
    case test1
    case test2
    case test3
}

我想知道是否有 Xcode 的快捷方式或命令可以快速编写:

switch test {
case .test1:
    /// ...
case .test2:
    /// ...
case .test3:
    /// ...
}

感谢您的帮助

【问题讨论】:

    标签: xcode enums switch-statement


    【解决方案1】:

    Xcode 12.5 在您键入时通过自动完成不提供此功能。但是,您可以使用建议 - “添加缺失的案例”来实现此目的。

    当您输入当前的Xcode 13 beta 时,这可以通过自动完成获得。 This tweet 展示了此功能的精美 GIF -

    【讨论】:

    • 这似乎只有在 color 直接传递到 switch 时才有效。由于某种原因,当 color 嵌套在结构中时,Xcode 无法建议任何自动完成,例如 switch someStruct.color 不会提供自动完成枚举案例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    相关资源
    最近更新 更多