TextChoiceQuestion 的 ResearchKit stepResult

ResearchKit stepResult for a TextChoiceQuestion

我正在使用 ResearchKit 的 stepResultForStepIdentifier 方法成功解决其他问题类型,但找不到正确的语法来预填充 TextChoiceQuestion 的结果。

下面是在 ORKCatalog 中为示例 TextChoice 问题设置结果的不成功尝试。对正确方法有什么建议吗?

func stepResultForStepIdentifier(stepIdentifier: String) -> ORKStepResult? {

    var stepResults = [ORKQuestionResult]()

    if stepIdentifier == "TextChoiceQuestionStep" {

        var questionDefault = ORKChoiceQuestionResult(identifier: stepIdentifier)

        questionDefault.choiceAnswers?.append("choice_2")

        stepResults.append(questionDefault)

    }

    var defaults = ORKStepResult(stepIdentifier: stepIdentifier, results: stepResults)

    return defaults
}

choiceAnswers数组是nil吗?当您执行 questionDefault.choiceAnswers?.append 时,choiceAnswers 可能是 nil,因此这可能什么都不做。

改为questionDefault.choiceAnswers = ["choice_2"]