Enum rawValueタイプエラー


異なるenumタイプをenumの元のタイプとして使用すると問題が発生します.
enum GameResult {
    case win
    case loss
    case tie
}

enum Game: GameResult {
    case 가위바위보 = GameResult.win
    case 묵찌빠 = GameResult.tie
}
enum GameResult: String {
    case win = "win"
    case loss
    case tie
}

enum Game: GameResult {
    case 가위바위보 = GameResult.win
    case 묵찌빠 = GameResult.tie
}

上の2つのコードのエラー文

  • 'Game' declares raw type 'GameResult', but does not conform to RawRepresentable and conformance could not be synthesized
  • Do you want to add protocol stubs?
  • Raw type 'GameResult' is not expressible by a string, integer, or floating-point literal
  • Raw value for enum case must be a literal
  • 元の値はテキスト値のみです.
    文字は何ですか.String or Int or Floating-point
    =enumタイプのcaseの元の値はliteralとして表すことはできませんか?
    String or Inter Floating-pointではなくenumタイプ?

    異種


    Swift Literals
    A literal is a representation of a value in source code, such as a number or a string. Swift provides the following kinds of literals: