Skip to content

Comments

Public beta release - SwiftUI#1585

Merged
simon-apple merged 1 commit intoResearchKit:dev/SwiftUIfrom
simon-apple:publicBetaRelease/SwiftUI
Oct 21, 2024
Merged

Public beta release - SwiftUI#1585
simon-apple merged 1 commit intoResearchKit:dev/SwiftUIfrom
simon-apple:publicBetaRelease/SwiftUI

Conversation

@simon-apple
Copy link
Contributor

ResearchKit SwiftUI

We are excited to announce the release of a new beta API for surveys in ResearchKit. This API is designed to enhance the flexibility, customization, and cross-platform compatibility of surveys in your ResearchKit apps. Below are the key features and usage details.

New Form APIs offer an easily configurable and flexible UI, with the same look and feel of ORKFormStep:

  • ResearchForm
    • Manages the navigation between steps in a survey.
  • ResearchFormStep
    • Represents a step in a survey and lays out the header and questions on one page. Question numbers (e.g. 1 of 3) are automatically added at the top of each question to denote progress in a step.
  • ResearchFormCompletion
    • Represents the context for a survey's completion
  • ResearchFormResult
    • Represents responses for the different kinds of questions.
  • StepHeader
    • A step header containing an image, title, and subtitle.
  • QuestionHeader
    • A question header containing a title and detail.
  • InstructionBodyItem
    • Displays an image and text side by side.
  • questionRequired (ViewModifier)
    • Designates a question as required or optional.

Survey Question Types:

  • MultipleChoiceQuestion
  • HeightQuestion
  • WeightQuestion
  • SliderQuestion
  • TextQuestion
  • DateTimeQuestion
  • NumericQuestion
  • ImageChoiceQuestion

The example below shows how to create a ResearchForm to present a text question for the participant to answer, and then save their results.

import ResearchKitSwiftUI

ResearchForm(
    id: "SurveyTask",
    steps: {
        ResearchFormStep(
            title: "Demographics",
            subtitle: "Tell us about yourself",
            content: {
                TextQuestion(
                    id: "textQuestion",
                    title: "What is your name?",
                    prompt: "Enter your name here",
                    lineLimit: .singleLine,
                    characterLimit: 0
                )
                .questionRequired(true)
            }
        )
    },
    onResearchFormCompletion: { completion in
        switch completion {
        case .completed(let results):
            save(results)
        case .discarded:
            cancel()
        default:
            cancel()
        }
    }
)

Install as an embedded framework

Download the project source code and drag in the ResearchKitSwiftUI folder. In the dialog that pops up, choose to copy files to destination and create folders. Then hit the finish button. Finally, embed the ResearchKitSwiftUI framework in your app by adding it to the "Frameworks, Libraries, and Embedded Content" section for your target.

Copy link

@jessi-apple jessi-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait for people to check this out! 🚀 Looks great ✅

@simon-apple simon-apple merged commit eedd39d into ResearchKit:dev/SwiftUI Oct 21, 2024
@simon-apple simon-apple deleted the publicBetaRelease/SwiftUI branch October 21, 2024 21:54
@SwiftNativeDeveloper
Copy link

SwiftNativeDeveloper commented Oct 24, 2024

Any desire to expose this as a Swift Package to make adoption easier?

Is this intended to be iOS 18+? I noticed the use of the new Group initializer added in iOS 18, this will be very limiting to teams that need to support a few earlier versions.

@jessi-apple
Copy link

Hi there @SwiftNativeDeveloper! Thank you for checking out our beta release of ResearchKit SwiftUI.

We do have plans to release a Swift Package once we move closer to release. Currently, we are still in beta.

We are also aware that currently this work requires iOS 18 APIs—this is part of why we are still in beta. We will be working to determine other ways to architect the API for backwards OS version compatibility. Thank you again for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants