The next Product College class starts January 2018. Apply Now

As always, we'll need to create a new Xcode project.

Create a new Xcode project

  1. Open Xcode and create a new project.
  2. Choose the Single View Application as template. Click next.
  3. Fill out the remaining info for your project. See the example provided below:
  4. Save your Xcode project somewhere you'll be able to easily find later. i.e. ~/Code/

Sample Project Info

Next we need to integrate Firebase into our project. To do this, we'll use a tool called CocoaPods. This will take care of all the third party libraries we rely on.

What Is a Dependency Manager?

One way of adding third-party code to your project would be to download all of the source code and copy it into your project.

This may sound straightforward, but in reality this approach will fail for many projects. Many third-party libraries come with their own dependencies and very special rules about how they need to be compiled; information that is not in the source files but in the project file of the library.

Even if that approach works, you will have a hard time updating the library. You will have to remove all code and add it again.

To avoid these kinds of problems, software developers have built dependency managers. The most popular one for iOS is CocoaPods.

How Does CocoaPods Work?

CocoaPods provides a huge repository of available iOS libraries. When you want to use CocoaPods you add a special file to your project in which you can list your dependencies. That file is called a Podfile.

If you want to use a library, you need to enter the name (and optionally the version) of the library into your Podfile. Then you can use one of the CocoaPods commands to install the library that you listed in the Podfile.

Creating a Podfile

In the Getting Started section, you should have already installed CocoaPods. If not, make sure to go back and follow the instructions to install CocoaPods.

After installing CocoaPods, we can create a Podfile that will allow us to declare dependencies for our project. The CocoaPods tool provides us with a convenient method to do this:

Open the root directory of your project in a terminal and type:

pod init

You can change directories to the root directory of your project by typing cd (make sure you put a space after cd) and then dragging the project folder into Terminal.

Now a Podfile with some skeleton content will be created. Open the Podfile in your favorite text editor. It should look like this:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

target 'Makestagram' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Makestagram

end

Installing Our Dependencies

Now we are ready to add our dependencies to this file.

Update your Podfile so that it looks like this. Note that we uncommented the platform :ios, '9.0' line. Also pay attention that you're using the correct single quotes.

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

target 'Makestagram' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'FirebaseUI/Auth'
  pod 'Firebase/Database'
  pod 'Firebase/Storage'
end

Then, return to the command line and run:

pod install

This step may take some time the first time you run it, up to 10 or 15 minutes.

Now your dependencies will be download and installed.

Verify that you have the correct version of each SDK by running pod update in the root directory of your Makestagram project. The Firebase CocoaPods should be at least 4.0.X. Verify Version

The next step is very important. After you have installed your first library, CocoaPods will generate an Xcode workspace for you. When using CocoaPods, you need to work with that workspace and no longer with the Xcode project that you have been working with.

Close your Xcode project. Then open the new workspace that CocoaPods has generated: image

As discussed earlier, this project contains all the frameworks we need. Additionally it contains a few source code files that we will use later as we progress through the tutorial.

We're now ready to dive into the first step - integrating and connecting our app to Firebase.

Feedback

If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations across the USA and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more