Reputation: 7605
class Question {
var type: QuestionType
var query: String
var answer: String
init(type: QuestionType, query: String, answer: String) {
self.type = type
self.query = query
self.answer = answer
}
}
enum QuestionType: String {
case trueFalse = "The sky is blue."
case multipleChoice = "Who is the ugliest Beatle: John, Paul, George or Ringo?"
case shortAnswer = "What is the capital of Oregon?"
case essay = "In 50 words, explain moleceular fusion"
static let types = [trueFalse, multipleChoice, shortAnswerm, essay]
}
enum AnswerType: String {
case trueFalse = "true"
case multipleChoice = "Sgt. Pepper"
case shortAnswer = "Salem"
case essay = "Molecular fusion happens when a daddy molecule and a mommy molecule love each other very much"
static let types = [trueFalse, multipleChoice, shortAnswerm, essay]
}
protocol QuestionGenerator {
func generateRandomQuestion() -> Question
}
class Quiz: QuestionGenerator {
func generateRandomQuestion() -> Question {
let randomNumeral = Int(arc4random_uniform(4))
let randomType = QuestionType.types[randomNumeral]
let randomQuery = randomType.rawValue
let randomAnswer = AnswerType.types[randomNumeral].rawValue
let randomQuestion = Question(type: randomType, query: randomQuery, answer: randomAnswer)
return randomQuestion
}
}
when I mouse over let randomAnswer = AnswerType.types[randomNumeral].rawValue, I see a popover that shows Error Type. I don't understand why Playground thinks there is an error
Upvotes: 2
Views: 62
Reputation: 3362
I copy paste your code in playground and the only error I see is the character 'm' at the end of 'shortAnswerm' in 'static let types' for both of your enum. Other than that everything is ok
Upvotes: 2