结构未使用

时间:2016-07-09 19:11:13

标签: ios swift struct

我有一个有50多个问题的应用。每个问题都有:

  1. 一个问题,
  2. 正确答案
  3. 三个不正确的答案
  4. 图片名称
  5. 所以我用这些属性制作了一个结构。屏幕上一次只会出现一个问题,所以我开始设置我的问题:

    let question1 = structName... (pass question info)
    let question2 = structName... (pass question 2 info)
    

    然而,这是一个“变量未使用”警告。我做错了什么,我该怎么做?

1 个答案:

答案 0 :(得分:0)

我无法将wrongAnswers组合成一个数组,但是我可以通过将所有结构存储在一个数组中来使用这个设计模式,这确保了它们都被使用了:

    //Question one
    let questionPackage = QuestionInfo(
        questionNum: 1,
        questionType: "Single",
        answer: "Correct answer here",
        wrongAnswer_1: "This is wrong",
        wrongAnswer_2: "So is this",
        wrongAnswer_3: "So is not right"
    )

    //Question two
    let questionPackage2 = QuestionInfo(
        questionNum: 1,
        questionType: "Single",
        answer: "Correct answer here",
        wrongAnswer_1: "This is wrong",
        wrongAnswer_2: "So is this",
        wrongAnswer_3: "So is not right"
    )

    let questionArray = [questionPackage,questionPackage2]
    let loadQuestion = questionArray[questionNum]