0

I am trying to create an enum that returns a struct and I am not succeeding . I have checked a few questions similar to mine e.g here, and this here and they do not address the issue I have. This is my code:

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")
        }
    }
}

Then I would like to use it like : Requests.cards.rawValue

kaddie
  • 233
  • 1
  • 5
  • 27

1 Answers1

1

That's because of your structure Roll doesn't conform Equatable protocol and you're trying to make a comparison of it, just change it to

struct Roll: Equatable {
    let times: String

    init(with times: String) {
        self.times = times
    }    
}
Dialogue
  • 311
  • 3
  • 5