我对调查结果的类型有问题。
如果我使用CareKit/HealthKit调查,当我想将其与ResearchKit调查混合使用时,一切都很好-我在以下方法中有错误:

func buildCarePlanResultFrom(taskResult: ORKTaskResult) -> OCKCarePlanEventResult {
    guard let firstResult = taskResult.firstResult as? ORKStepResult,
        let stepResult = firstResult.results?.first else {
            fatalError("Unexepected task results")
    }
    if let numericResult = stepResult as? ORKNumericQuestionResult,
        let answer = numericResult.numericAnswer {
        return OCKCarePlanEventResult(valueString: answer.stringValue, unitString: numericResult.unit, userInfo: nil)
    } else {

    }

    fatalError("Unexpected task result type")
}

我想这是因为我不能做一个OCKCarePlanEventResult对象[答案和数字结果都是零]。
我更新以下扩展中的症状跟踪器:
extension TabBarViewController: ORKTaskViewControllerDelegate {
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith
    reason: ORKTaskViewControllerFinishReason, error: Error?) {
    defer {
        dismiss(animated: true, completion: nil)
    }
    guard reason == .completed else { return }
    guard let symptomTrackerViewController = symptomTrackerViewController,
        let event = symptomTrackerViewController.lastSelectedAssessmentEvent else { return }
    symptomTrackerViewController.progressRingTintColor = .lightGreen
    symptomTrackerViewController.delegate = self
    let carePlanResult = carePlanStoreManager.buildCarePlanResultFrom(taskResult: taskViewController.result)
    carePlanStoreManager.store.update(event, with: carePlanResult, state: .completed) {
        success, _, error in
        if !success {
            print(error?.localizedDescription)
        }
    }
}}

有什么建议如何将ResearchKit的结果类型转换为CareKit或其他解决方案来更新视图?
也许,这会有帮助,任务示例:
    let sleepHoursSurveyActivity = OCKCarePlanActivity.assessment(
        withIdentifier: ActivityIdentifier.sleepHours.rawValue,
        groupIdentifier: nil,
        title: "Sleep Hours",
        text: nil,
        tintColor: .darkGreen,
        resultResettable: true,
        schedule: dailyScheduleRepeating(occurencesPerDay: 1),
        userInfo: ["ORKTask" : AssessmentTaskFactory.sleepHoursSurveyAssessmentTask()])

static func sleepHoursSurveyAssessmentTask() -> ORKTask {
    var steps = [ORKQuestionStep]()
    let question = NSLocalizedString("How many hours did you sleep?", comment: "")
    let textChoices = [
        ORKTextChoice(text: "1-3", value: "1-3" as NSString),
        ORKTextChoice(text: "4-5", value: "4-5" as NSString),
        ORKTextChoice(text: "6-7", value: "6-7" as NSString),
        ORKTextChoice(text: "8", value: "8" as NSString),
        ORKTextChoice(text: "more than 8", value: "more than 8" as NSString)
        ]

    let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: textChoices)
    let sleepHoursSurvaySteps = ORKQuestionStep(identifier: "sleepHours", title: question, answer: questAnswerFormat)
    sleepHoursSurvaySteps.isOptional = false
    steps += [sleepHoursSurvaySteps]

    return ORKOrderedTask(identifier: "sleepHoursSurveyTask", steps: [sleepHoursSurvaySteps])
}

最佳答案

返回任务的函数sleepHoursSurveyAssessmentTask没有数字应答格式。您使用的是ORKTextChoiceAnswerFormat,可以使用ORKTaskResultORKChoiceQuestionResult中提取。

关于ios - CareKit和ResearchKit冲突,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50775109/

10-09 07:56