2015-06-04 22 views
0

我對其他問題類型成功使用了ResearchKit的stepResultForStepIdentifier方法,但無法找到正確的語法來預先填充TextChoiceQuestion的結果。ResearchKit對於TextChoiceQuestion的stepResult

以下是在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 
} 

回答

1

是在choiceAnswers陣列nil?當你做questionDefault.choiceAnswers?.appendchoiceAnswers可能是nil,所以這可能什麼都不做。

反而做questionDefault.choiceAnswers = ["choice_2"]

+0

謝謝。這樣可行。我添加了一個用於檢查所述陣列是否是nil - '如果questionDefault.choiceAnswers ==零{ questionDefault.choiceAnswers = [ 「choice_2」] }否則{ questionDefault.choiceAnswers .append( 「choice_2」) ?}' – Brendenw

相關問題