Я делаю несколько анкет.В общем, я создал модель, в которой полностью прописал вопросы и ответы, как и должно быть на самом деле.Но какая обработка должна быть в заявке, если я хочу не только задавать вопросы один за другим, но и задавать конкретный уникальный вопрос в зависимости от последнего ответа?(вероятно, это называется «вопросник с выбором переплетенных ответов») Появление следующего вопроса или результата будет зависеть от последнего ответа.Как реализовать это в модели?
Я хочу сделать так же, как в этой схеме .
struct PossibleAnswer {
var text: String
var type: TypeOfLanguage
var nextQuestion: Question?
}
enum TypeOfLanguage: String {
case python = "Python"
case java = "Java"
case c = "C"
case cPlusPlus = "C++"
case javaScript = "JavaScript"
case cSharp = "C#"
case ruby = "Ruby"
case php = "PHP"
case swift = "Swift"
case next
var definition: String {
switch self {
case .python:
return "Some text"
case .java:
return "Some text"
case .c:
return "Some text"
case .cPlusPlus:
return "Some text"
case .javaScript:
return "Some text"
case .cSharp:
return "Some text"
case .ruby:
return "Some text"
case .php:
return "Some text"
case .swift:
return "Some text"
case .next:
return ""
}
}
}
struct Question {
var text: String
var answers: [PossibleAnswer]
static func loadData() -> [Question] {
return [Question(text: "Why do you want to learn programming?", answers: [
PossibleAnswer(text: "For my kids", type: .python, nextQuestion: nil),
PossibleAnswer(text: "Make money", type: .next, nextQuestion:
Question(text: "Make money", answers: [
PossibleAnswer(text: "Get a job", type: .next, nextQuestion:
Question(text: "Which platform/field?", answers: [
PossibleAnswer(text: "I want to work for big tech companies", type: .next, nextQuestion:
Question(text: "Which one?", answers: [
PossibleAnswer(text: "Facebook", type: .python, nextQuestion: nil),
PossibleAnswer(text: "Google", type: .python, nextQuestion: nil),
PossibleAnswer(text: "Microsoft", type: .cSharp, nextQuestion: nil),
PossibleAnswer(text: "Apple", type: .swift, nextQuestion: nil)])),
PossibleAnswer(text: "Doesn't matter, i just want money!", type: .java, nextQuestion: nil)]))]))])]}}