Swift 为什么我的enum会说;ErrorType“;
当我将鼠标悬停在randomAnswer=AnswerType.types[RandomNumeric].rawValue上时,我看到一个弹出框显示错误类型。我不明白为什么Playerd认为有错误我在Playerd中复制粘贴了您的代码,我看到的唯一错误是两个枚举的“static let types”中“shortAnswerm”末尾的字符“m”。除此之外,一切正常我将您的代码复制粘贴到游乐场,我看到的唯一错误是两个枚举的“static let types”中“shortAnswerm”末尾的字符“m”。除此之外一切都好。谢谢。把它作为答案贴出来,我会把它标对的。谢谢Swift 为什么我的enum会说;ErrorType“;,swift,enums,xcode9,Swift,Enums,Xcode9,当我将鼠标悬停在randomAnswer=AnswerType.types[RandomNumeric].rawValue上时,我看到一个弹出框显示错误类型。我不明白为什么Playerd认为有错误我在Playerd中复制粘贴了您的代码,我看到的唯一错误是两个枚举的“static let types”中“shortAnswerm”末尾的字符“m”。除此之外,一切正常我将您的代码复制粘贴到游乐场,我看到的唯一错误是两个枚举的“static let types”中“shortAnswerm”末尾的字符
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
}
}