Setting up Your Project to Use CareKit

Add and update CareKit in your project using Swift Package Manger.

Overview

CareKit is an open-source framework, so it’s not provided with the developer tools supplied in Xcode. To use it, you need to add it to your project as a dependency. The framework can be added using the Swift Package Manager in Xcode, which allows you to easily keep it up to date.

You can find CareKit as a repository on GitHub: CareKit on GitHub.

Add CareKit as a Package Dependency

Add a package dependency to your Xcode project by selecting File > Swift Packages > Add Package Dependency. Next, you need to provide the URL of the repository: https://github.com/carekit-apple/CareKit

Choose Package Options

With the package repository specified, choose which version, branch, or commit from which to pull. Unless there’s a specific commit from which you want to pull, choose the main branch. For more information on specifying versions, branches, and commits, see Adding Package Dependencies to Your App.

Select Parts of CareKit You Want to Use

CareKit is built to be modular, and this includes being able to use only the parts relevant to your needs. The framework includes a complete set of libraries, pre-built view controllers, the data store, and the component views. It also uses Combine to synchronize events between the UI and data layers.

CareKit includes CareKitUI and CareKitStore. If you only want to use the customizable views, choose to just include CareKitUI, or if you only need access to the data-persistence library, choose to just include CareKitStore.

In the ‘Choose package products and targets’ dialogue, select which part or parts you want, and the targets to which they should be added:

[Image]

Verify the Dependency

To check whether the dependency has been successfully included in your project, select your project in the Navigator, select the target, and under General scroll down to Frameworks, Libraries, and Embedded Content. You should see CareKit listed there:

[Image]

If you’d like to remove CareKit from your target, select it in the list and then press the removal button, which is the minus (-) sign.

Once you’ve added CareKit to your target, use it in any of your classes by importing it:

import CareKit

Update CareKit

Swift Package Manager makes it easy to keep your dependencies up to date. Every time you open a Xcode project that has CareKit included as a dependency and you have an active internet connection, the Swift Package Manager checks for updates that match your specified rules for version, branch, or commit.

You can also manually check for an update in Xcode by selecting File > Swift Packages > Update to Latest Package Versions:

[Image]

Add Localizations from CareKit

The Swift Package Manger currently doesn’t support including resources, so you’ll need to add the localization files from the CareKit framework to your project manually.

To do this, in the project navigator pane, find the ‘Swift Package Dependencies’ section and click the disclosure triangle to expand the contents. Navigate to the ‘Localization’ folder, and right-click it. In the menu, select ‘Show in Finder’ to reveal the localizations folder in the file system:

[Image]

Next, drag the Localization folder from Finder into your project inside Xcode. In the ‘Choose options’ dialogue, tick the ‘Copy items if needed’ option, then click finish:

[Image]

After you click Finish, your project contains the Localization folder and its contents.