【发布时间】:2020-09-20 09:06:06
【问题描述】:
let questions = ["____ Book","File ____"]
let answers = [["Read","Heed","Write","Say"],["lawsuit", "acquisition", "care","office"]]
var answerDict:[String:[Int:Any]] = [String:[Int:Any]]()
var answerChosen:[String] = [String]()
// variables
// keeps track of what qs we at
var currentQuestion = 0
var rightAnswerPlacement:UInt32 = 0
//var for counting number of time users press button
var ActionCount: Int = 0
//struc for parsing the qs
struct report {
var question : String
var AnswersChosen : [String] = [String]()
var userCount : Int
上面是我将结构引入我的测验应用程序的地方。我的结构包括用户当前打开的问题,AnswersChosen 是用户在获得正确问题之前为该问题选择的选项,最后 userCount 是他尝试的次数
//creating array of report struct
var currentReport = [report]()
//currentReport.append(report(question:questions , AnswersChosen:[String](), userCount:0))
//array for what users are selecting
answerChosen.append(sender.title(for: .normal)!)
//print (answerChosen)
//currentReport.AnswersChosen = answerChosen
print(answerChosen)
//counting number of times wrong button is pressed
ActionCount += 1
//currentReport.userCount = ActionCount
print(ActionCount)
currentReport.append(report(question:questions[currentQuestion] , AnswersChosen:answerChosen, userCount:ActionCount))
print(currentReport)
这是我写下函数和结构实例的地方。目前,这段代码的输出给了我:
这不是我要寻找的输出。因此,我的问题是如何编辑我的代码,以便我能够为每个问题创建一个“报告”,并且每个报告中的 AnswersChosen 仅来自用户当前所在的问题
【问题讨论】: