Advanced ResearchKit project setup

Friday, 12 February 2016 in dev journal by Vincent Tourraine

In our article How to setup a ResearchKit project, we have detailed the process of creating and configuring an Xcode project to build a ResearchKit app.

Once you get comfortable with this workflow, it becomes interesting to combine it with more advanced techniques, to improve its efficiency and reliability.

Git Submodule

ResearchKit isn’t part of the system frameworks, so you need to download it to integrate it into your project.

But ResearchKit is constantly being improved, and new features are frequently being added in. So you might want to incorporate these changes during the lifespan of your project. You could just reopen the GitHub page, download the ZIP archive, and overwrite your local files.

A simpler way to accomplish that is to setup a “Git Submodule”. It takes more efforts to configure it the first time, but then it becomes a lot faster to update the code.

Your project will have to belong to a “Git repository” first. Xcode can do that for you, when you initially create the project. When you select its location on your machine, there’s an option at the bottom labeled “Source Control: Create Git repository”. Once you’ve checked this box, your project will be attached to a local Git repository. If you’ve already created the project without that option, you can still set it up at any time. Open Terminal, then move to your project location. Then, simply enter git init.

$ cd ~/MyXcodeProjectLocation/
$ git init
Initialized empty Git repository in ~/MyXcodeProjectLocation/.git/

Now let’s configure our repository to point to the online ResearchKit repository. With the Terminal, move to your project location, and “add” the submodule:

$ cd ~/MyXcodeProjectLocation/
$ git submodule add

As you can see, we’re using the GitHub project URL. This operation will create a subfolder named “ResearchKit”, and download all the relevant content.

It gets really interesting when you want to update that folder. Move inside the ResearchKit folder, then ask Git to “pull” the latest changes:

$ cd ResearchKit/
$ git pull

This will automatically download everything that has been changed. And only what’s been changed, so you don’t need to re-download everything every time.

You can learn more about this tool, with tutorials and a complete documentation, from the official Git website.


There’s another solution to integrate ResearchKit to your Xcode project, by using an iOS dependency manager called CocoaPods. The nice thing is that not only will it download and update the source code, but it will also configure the project for you, so you’ll be able to skip the corresponding section of our “setup” article.

First, you need to install CocoaPods. It only takes one command for the Terminal:

$ sudo gem install cocoapods

Then, create a new text file in your project folder, and name it “Podfile”. This is where you declare your app dependencies, represented by so-called “pods”. Add the following content:

platform :iOS, '8.0'

target 'MyApp' do
  pod 'ResearchKit', '~> 1.0'

Make sure to replace “MyApp” with the actual app target for your app (by default, it’s the “Product Name” chosen during the project creation).

Now go back to the Terminal, and ask CocoaPods to install the project dependencies (in our case, that’s ResearchKit):

$ pod install

From this moment on, you will need to use the Xcode “workspace” created by CocoaPods. As far as we’re concerned, it is very similar to the project we initially created, but also includes ResearchKit, with everything configured and ready to use.

The right tool for the job

This couple of techniques are often used to streamline the development workflow of iOS apps.

You should consider using them, depending on the scale of your project, and the people involved. Sometimes the simpler approach works best, and sometimes specialized tools such as Git and CocoaPods can provide tremendous improvements and save you a lot of time and efforts.