Parse Backend with Swift!

So you have the next best app idea and you begin coding! Next thing you realize is that you need a way to store photo's, files, array's, strings and dates in the cloud but you don't know how to set up a server. What do you do? You turn to a great ready to use tool called Parse.

With Parse you can instantly add a powerful cloud database, push notification services, and analytics tracking to your app. - Parse.com

So how do you get started? Follow along and by the end of the tutorial you will be able to add the ParseSDK to your project, have the database and your app talking also setting up a user in the cloud.

This tutorial assumes you know how to set up an xcode project.

Step 1: Set up a blank xcode project titled 'Parse Example'

Step 2: Set up Cocoapods

CocoaPods

The first item of business we must take care of is setting up Cocoapods. Cocoapods you can think of as a third party framework manager.

Using the terminal:

  1. $ cd into your project directory.
    Create a Podfile. This can be done by running $ vim podfile .
  2. In terminal type $ vim podfile
    alt
  3. In your podfile type:
    alt

    platform :ios, '7.0'

    pod 'Parse'

Save your podfile.
4. In terminal type $ pod install
alt 5. Finished!
alt

Opening your project

Next close your terminal and go into your project directory. You will now see an xcode.proj and xcode.xcworkspace. You must open .xcworkspace to use the new frameworks.

In order to use Parse we'll have to set up a few items:

Step 1. Add these frameworks in xcode. First click on project, go to Build Phases, and find Link Binary with Libraries and add these frameworks:

AudioToolbox.framework
CFNetwork.framework
CoreGraphics.framework
CoreLocation.framework
libz.dylib
MobileCoreServices.framework
QuartzCore.framework
Security.framework
StoreKit.framework
SystemConfiguration.framework
libsqlite3.dylib

alt

Step 2. We need to add a Bridging Header File. This is a file that will help us bridge the framework with Parse.

  1. Go to File and select: New
  2. Choose Objective-C File
    alt
  3. Name it 'ParseBridgingHeader'
  4. Choose Next and save. You will be asked if you would like to use this file as an Objective-C bridging header file, choose Yes.
  5. It will add two files a .m and a .h. You can delete the .m
  6. In the .h add "#import Parse/Parse.h>" This will import Parse into your project!!

alt

Done!
alt

Using Parse

  1. Now before we begin coding we must now set up our backend server. So go to Here and register, if you already are registered go to next step!
  2. After you sign in click on the dashboard and create a new app. Name it whatever you like and click create.
  3. Click on your app and go to settings. Under settings you will see a navigation panel on the left. Click keys. Here you will see the Application ID key and the client key. you will need these in the next section.

alt

Coding Time

Now that our app has a backend server set up, we need to tell the app about it. To do this we will add our keys from the previous section. Go to your app delegate file In the didFinishLaunchingWithOption function add this function.

Parse.setApplicationId(“yourapplicationkey”, clientKey: “yourclientkey”)

Next go to your viewController.swift file.

This next piece of code will make a new class and upload it to the cloud. This will test and see if everything set up so far is valid.

var object = PFObject(className: "TestClass") object.addObject("iOS-Developers", forKey: "bestSlackGroup")
object.addObject("iPhone", forKey: "bestSmartPhone")
object.save()

alt

Now go to your app on parse.com and you will see a brand new class with the values we filled in!! If you do not see the class or experience an error, make sure your keys are correct. If they are correct make sure the Parse.framework is added correctly.

alt

You've just connected your first backend with swift!
alt

Whats Next?

In future tutorials I will walk you through using the iPhones camera and uploading images to parse, as well as displaying information coming from parse. Next tutorial will be creating a user and a mini profile!