目前我正在使用研究工具包构建一个应用程序。下面是我的问题。
let onsetQuestionStepTitle = "Title"
let onsetQuestionStepQuestion = "Question Name"
let onsetTextChoices = [
ORKTextChoice(text: "superb", value: 0 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "great", value: 1 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "fair", value: 2 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "not good", value: 3 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "bad", value: 4 as NSCoding & NSCopying & NSObjectProtocol)
]
let onsetAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: onsetTextChoices)
let onsetQuestionStep = ORKQuestionStep(identifier: "twoAwakeSurvey", title: onsetQuestionStepTitle, question: onsetQuestionStepQuestion, answer: onsetAnswerFormat)
steps += [onsetQuestionStep]
如果用户点击精湛,我想跳到带有标识符“threeAwakeSurvey”的下一步并转到“fourAwakeSurvey”。为此,我实现了以下代码。
var task = ORKNavigableOrderedTask(identifier: "StepNavigationTaskIdentifier", steps: steps)
let resultSelector: ORKResultSelector = ORKResultSelector(resultIdentifier: "twoAwakeSurvey")
let askLocation = ORKResultPredicate.predicateForChoiceQuestionResult(with: resultSelector, expectedAnswerValue: 0 as NSCoding & NSCopying & NSObjectProtocol)
let locationNavigationRule = ORKPredicateSkipStepNavigationRule(resultPredicate: askLocation)
task.setSkip(locationNavigationRule, forStepIdentifier: "threeAwakeSurvey")
但是,这是行不通的。我阅读了文档,但仍然不明白为什么。