Swift ResearchKit HealthKit QuestionStep

Swift ResearchKit HealthKit QuestionStep

我目前正在 swift 开发基于 ResearchKit 框架(用 objective-c 编写)的医学研究应用程序。我目前正在尝试创建一个带有 HealthKit 问题的调查。我现在拥有的代码是:

    let genderAnswerFormat = ORKHealthKitCharacteristicTypeAnswerFormat(characteristicType: HKCharacteristicTypeIdentifierBiologicalSex)
    let genderQuestionStepTitle = "What is your gender?"
    let genderQuestionStep = ORKQuestionStep(identifier: "genderQuestionStep", title: genderQuestionStepTitle, answer: genderAnswerFormat)
    steps += [genderQuestionStep]

然而,第一行导致错误:

无法为 'ORKHealthKitCharacteristicTypeAnswerFormat' 找到接受类型为“(characteristicType: String)”的参数列表的初始值设定项

您需要将标识符转换为 HKObjectType,这是初始化程序的预期参数类型。