Swift x27型表达模式;滚动';无法匹配类型为';请求。RawValue';(又名翻滚)

Swift x27型表达模式;滚动';无法匹配类型为';请求。RawValue';(又名翻滚),swift,struct,enums,Swift,Struct,Enums,我试图创建一个返回结构的枚举,但没有成功。我已经检查了一些与我的问题类似的问题,例如,这和他们没有解决我的问题。这是我的代码: import Foundation struct Roll { let times: String init(with times: String) { self.times = times } } fileprivate enum Requests { case poker case cards

我试图创建一个返回结构的枚举,但没有成功。我已经检查了一些与我的问题类似的问题,例如,这和他们没有解决我的问题。这是我的代码:

import Foundation

struct Roll {
    let times: String

    init(with times: String) {
        self.times = times
    }

}

fileprivate enum Requests {
    case poker
    case cards
    case slots
}

extension Requests: RawRepresentable {

    typealias RawValue = Roll

    init?(rawValue: RawValue) {
        switch rawValue {
        case Roll(with: "once"): self = .poker
        case Roll(with: "twice"): self = .cards
        case Roll(with: "a couple of times"): self = .slots
        default: return nil
        }
    }

    var rawValue: RawValue {
        switch self {
        case .poker: return Roll(with: "once")
        case .cards: return Roll(with: "twice")
        case .slots: return Roll(with: "a couple of times")
        }
    }
}


然后我想像这样使用它:
Requests.cards.rawValue

这是因为您的结构
Roll
不符合
equalable
协议,您试图对其进行比较,只需将其更改为

struct Roll: Equatable {
    let times: String

    init(with times: String) {
        self.times = times
    }    
}