Swiftpack.co - tryterra/TerraSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tryterra.
tryterra/TerraSwift v1.0.5
Swift Framework for Apple Health Integration with Terra Enabling Developers LTD.
⭐️ 5
🕓 Yesterday
.package(url: "https://github.com/tryterra/TerraSwift.git", from: "v1.0.5")


This library allows developers to connect to TERRA through Swift (implemented with Swift5.0). This library uses HealthKit for iOS v13+. It thus would not work on iPad or MacOS or any platform that does not support Apple HealthKit. (Must have signing capabilities for Healthkit)

Also must include the following keys in your Info.plist file: Privacy - Health Share Usage Description and Privacy - Health Records Usage Description

The package must be added as a dependency to your project. This can be done simply by editting your App's dependencies and adding TerraSwift as a dependency with the following location: https://github.com/tryterra/TerraSwift.git.

You may now import the package using: import TerraSwift


As default, we have enabled all our required healthkit HKObjectTypes for the functionality of the whole package. However if there are healthkit parameters for which you do not wish to be included, you may input a custom set of HKObjectTypes as a subset of the following:

  • Workouts
  • Activity Summary
  • Active Energy Burnt
  • Step Count
  • Heart Rate
  • Heart Rate Variability in SDNN
  • Vo2Max
  • Height
  • Apple Exercise Time
  • Body Mass
  • Flights Climbed
  • Body Mass Index
  • Body Fat Percentage
  • Distance Swimming
  • Distance Cycling
  • Distance Walking/Running
  • Biological Sex
  • Date of Birth
  • Basal Energy Burned
  • Swimming Stroke Count
  • Resting Heart Rate
  • Blood Pressure Diastolic
  • Blood Pressure Systolic
  • Body Temperature
  • Lean Body Mass
  • Oxygen Saturation
  • Sleep Analysis
  • Respiratory Rate
  • Workout Route

This set can then passed as the parameter readTypes when initiating the Terra Client as shown below.


Start by connecting to Terra through our API as documented here. To make this easier, there is a function provided by this package which allows your users to connect with Terra. By simply giving us your dev-id and X-API-Key that we provide for you when you sign up with us, you can register a user by simply running this function:

var userId: String = TerraSwift.connectTerra(dev_id: "YOUR_DEV_ID", xAPIKey: "YOUR_API_KEY")

This will return a userId for which you may now use to acquire data with.

Using this user ID, you may now create a Terra Client as such:

var TerraClient: TerraSwift.Terra = TerraSwift.Terra(user_id: user_id, dev_id: "YOUR_DEV_ID", xAPIKey: "YOUR_API_KEY", auto: true, readTypes: "YOUR_CUSTOM_HKOBJECT_SET")

Upon initializing, the Client will automatically push workout details of the user to your callback url everytime they open your application. It will also automatically push Daily, Sleep, and Body Data to your callback url every 8 hours. However this can only occur when the user enters your application. This feature is controlled by the auto parameter. By default, it is set to true. However if you wish to make other timed requests, you may create your own timer and use the functions described below while setting auto to false.


You may also request for specific data from specific days using the built in functions.

The following functions will push data to your webhook URL from between the given startDate and endDate parameters:

Body Data

TerraClient.getBody(startDate: Date, endDate: Date)

Daily Data

TerraClient.getDaily(startDate: Date, endDate: Date)

Sleep Data

TerraClient.getSleep(startDate: Date, endDate: Date)

Activity Data

TerraClient.getWorkout(startDate: Date, endDate: Date)

The following function will push athlete data to your webhook URL. (No parameters required)

For Athlete Data



To deauthorize a user, please follow our Deauthentication Endpoint on the Docs. To make this easier, we have addded a function within the package to this:



Stars: 5
Last commit: Yesterday
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics