Skip to content
No description, website, or topics provided.
Swift Other
  1. Swift 99.1%
  2. Other 0.9%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Starter App.xcodeproj
Starter App.xcworkspace moving to cocoa pods due to issues with adding CDTDatastore and Carthage Jun 25, 2016
Starter App

Starter iOS App


The starter app has the ability to pull data from HealthKit, store it locally, and sync with the server. As an added bonus, the iOS application can also read in data from CSV files (in a specific format) and store it locally.


  1. CocoaPods


  1. Run pod install in the root directory of the project
  2. Open the .xcworkspace file and Build & Run


Three operations will occur when the app is launched:

  • Sync with Server (ServerSync.swift)
  • Sync with HealthKit (HealthKitSync.swift)
  • Download and Store CSV Data (CSVDataSync.swift)


Check out HealthKitSync.swift and HealthKitManager.swift to see how we are working with HealthKit.

HealthKitSync pulls data down from HealthKit and stores it in Realm; it will not push data into HealthKit. If you would like to store data into HealthKit, check out saveRealmData_ToHealthKit() in HealthKitSync.swift.

If you would like to add support for handling new data types from HealthKit, do a project wide search for this text //TODO-ADD-NEW-DATA-TYPE. These are all the places where you would need to add new strings, constants, logic, and etc for your new data type.


If you are including a server component into your system, the app will sync all data with the NodeJS/CloudantDB server. See the Starter NodeJS page for more information on getting that setup.

Check out ServerSync.swift to see more details. We are using the swift-cloudant library to facilitate pulling down and store objects in the CloudantDB (on our NodeJS server).


Create a new set of credentials in your Cloudant DB Admin page or use the one that was created during the Starter NodeJS setup. Fill out these credentials in ServerSync.swift.

Download and Store CSV Data

We also download and store CSV data in Realm (which gets synced up to the server) when you specify CSV files in the urlsArr in CSVDataSync.swift. The CSV data must be in a specific format to get parsed.



The database we are using for local storage is Realm: You should check it out even if you are not using the starter apps!

Data Model

The data model only consists of two model classes: HealthData and HealthDataModel. Although this seems generic and simplistic, it allows us to store data from almost all data types.


class HealthData: Object {
    dynamic var id: String = UUID().uuidString
    dynamic var source: String = ""
    dynamic var date: Date = Date()
    dynamic var type: String = ""
    dynamic var participantId: String = ""
    dynamic var sessionId: String?
    let dataObjects = LinkingObjects(fromType: HealthDataValue.self, property: "healthObject")

HealthData stores generic health information (e.g. date, type, source, etc). This object does not store the actual data values; this is persisted in HealthDataValue. HealthData is loosely linked with HealthDataValue through LinkingObjects.


class HealthDataValue: Object { 
    dynamic var healthObject: HealthData?
    dynamic var label: String?
    dynamic var value: String?

HealthDataValue stores specific health values and labels for those values. It's linked to a HealthData object.


class DataDownloadRecord: Object {
    dynamic var url: String?
    dynamic var date: NSDate?

DataDownloadRecord is used to keep track of the CSV files have been downloaded. This is to make sure we do not download the CSV file twice on app launch.

You can’t perform that action at this time.