ios - Swift:如何实现字符串数组的枚举

标签 ios enums swift5.2 xcode11.4

我正在尝试实现这样的字符串数组的枚举

import UIKit

enum EstimateItemStatus: Int, [String] {
    case Pending
    case OnHold
    case Done

    var description: [String] {
        switch self {
        case .Pending:
            return ["one", "Two"]
        case .OnHold:
            return ["one", "Two"]
        case .Done:
            return ["one", "Two"]
        }
    }
}

print(EstimateItemStatus.Pending.description)

但我收到此错误:
error: processArray.playground:3:31: error: multiple enum raw types 'Int' and '[String]'
enum EstimateItemStatus: Int, [String] {
                         ~~~  ^

你们谁都知道如何解决此错误以使枚举起作用?

非常感谢您的帮助。

最佳答案

从枚举声明中删除[String]

enum EstimateItemStatus: Int {
    case Pending
    case OnHold
    case Done

    var description: [String] {
        switch self {
        case .Pending:
            return ["one", "Two"]
        case .OnHold:
            return ["one", "Two"]
        case .Done:
            return ["one", "Two"]
        }
    }
}

关于ios - Swift:如何实现字符串数组的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61552648/

相关文章:

java - 如何避免 java 中的重复枚举值?

java - 函数枚举

ios - 尾随约束

ios - 使用来自 clang 的 @import?

ios - 创建自定义 "tickle"UIGestureRecognizer 的最佳方法是什么?

ios - 获取所选 map 的边界框

mysql - Postgres "ERROR: XX000: cache lookup failed for type 0 LOCATION: format_type_extended, format_type.c:128"?

swift - 在 SwiftUI 中动态获取 Shape 以供查看

ios - RxSwift : single observable self is nil