Skip to content

Instantly share code, notes, and snippets.

@d2burke
Created June 10, 2023 13:59
Show Gist options
  • Save d2burke/53375c346b49c61597ca9cb400d47d7c to your computer and use it in GitHub Desktop.
Save d2burke/53375c346b49c61597ca9cb400d47d7c to your computer and use it in GitHub Desktop.
This code seems like it should compile, conceptually, but it doesn't. Compiler says JobApplication doesn't conform to Hashable.
struct JobApplication: Hashable, Identifiable {
var id: String
var jobPostingId: String
var answers: [CustomQuestionAnswer]
var questions: [CustomQuestion]
}
protocol CustomQuestion: Hashable, Identifiable {
var id: String { get set }
var prompt: String { get set }
var required: Bool { get set }
}
struct BoolQuestion: CustomQuestion {
var id: String
var prompt: String
var required: Bool
}
struct TextQuestion: CustomQuestion {
var id: String
var prompt: String
var required: Bool
var length: Int
}
struct NumericQuestion: CustomQuestion {
var id: String
var prompt: String
var required: Bool
var minimum: Int
var maximum: Int
}
protocol CustomQuestionAnswer: Hashable, Identifiable {
var id: String { get set }
}
struct BoolCustomQuestionAnswer: CustomQuestionAnswer {
var id: String
var question: BoolQuestion
var value: Bool
}
struct TextCustomQuestionAnswer: CustomQuestionAnswer {
var id: String
var question: TextQuestion
var value: String
}
struct NumericCustomQuestionAnswer: CustomQuestionAnswer {
var id: String
var question: NumericQuestion
var value: Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment