Skip to content

netreconlab/CareKitEssentials

CareKitEssentials

Documentation Documentation Tuturiol Xcode 16.1+ ci codecov License

Provides essential cards, views, models, protocols, and extensions to expedite building CareKit based applications. If you are using CareKit models in SwiftUI views, CareKitEssentials adds a number of extensions to CareKit models to enable your views to update properly. Simply add import CareKitEssentials to each of your SwiftUI view files and your SwiftUI views will start working correctly.

Entensions

A number of public extensions are available to make using CareKit easier. All of the extensions can be found in the Extensions and Cards/Shared/Extensions folders.

Usage

You can create SwiftUI views that conform to CareKitEssentialView to obtain a number of convenience methods for saving and deleting outcomes. The framework adds a number of additional cards that can be found in the Cards folder. The following add views/cards are based on CareKitEssentialView:

watchOS

DigitalCrownView can be used to quickly create a view that responds to the crown

image

Shared

SliderLogTaskView can be used to quickly create a slider view

image

CareEssentialChartView to create charts from CareKit data based on SwiftUI Charts.

image

Easily create surveys with ResearchKitSwiftUI for all supported platforms. Learn how to create your own surveys here.

image image

Use EventQueryView and EventQueryContentView to display SwiftUI views inside of CareKit UIKit views such as OCKDailyPageViewController's. Some examples are below:

// Displaying the out-of-the-box `NumericProgressTaskView`
let card = EventQueryView<NumericProgressTaskView>(
					query: query
)
.formattedHostingController()

return card

// Displaying a ResearchKitSwiftUI survey card
let surveyViewController = EventQueryContentView<ResearchSurveyView>(
			query: query
		) {
			EventQueryContentView<ResearchCareForm>(
				query: query
			) {
				ForEach(steps) { step in
					ResearchFormStep(
						image: step.image,
						title: step.title,
						subtitle: step.subtitle
					) {
						ForEach(step.questions) { question in
							question.view()
						}
						.tint(tintColor)
					}
				}
			}
			.tint(tintColor)
		}
		.tint(tintColor)
		.formattedHostingController()
return surveyViewController

// Extension to make life easier
private extension View {
    /// Convert SwiftUI view to UIKit view.
    func formattedHostingController() -> UIHostingController<Self> {
        let viewController = UIHostingController(rootView: self)
        viewController.view.backgroundColor = .clear
        return viewController
    }
}