小编pan*_*gam的帖子

协议类型“Any”的值不能符合“Equatable”;只有 struct/enum/class 类型可以符合协议

协议类型“Any”的值不能符合“Equatable”;只有 struct/enum/class 类型可以符合协议

值的类型为“ANY”,因为它可以是 Int 或 String。所以无法实现Equatable协议。

struct BusinessDetail:Equatable {
    static func == (lhs: BusinessDetail, rhs: BusinessDetail) -> Bool {
        lhs.cellType == rhs.cellType && lhs.value == rhs.value
    }
    
    let cellType: BusinessDetailCellType
    var value: Any?
}

enum BusinessDetailCellType:Int {
    case x
    case y

    var textValue:String {
        Switch self {
        case x:
            return "x"
        case y:
            return "y"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

enums struct ios swift equatable

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

enums ×1

equatable ×1

ios ×1

struct ×1

swift ×1