Show Menu

Looking for an iOS Developer?

Submit your 30 day Job Listing for FREE

parse com logo

Parse.com is an absolutely fantastic option for the individual Swift iOS developer who wants to have the full power of a server backend powering their app without all the difficulties of setting one up. This tutorials shows you how to connect your Swift iOS Application to the Parse.com service.

This tutorial assumes that you have at least a basic understanding of the Swift programming language, the structure of Xcode projects and finally how to create a new single view application in Xcode 6. If you need to be refreshed on any of these head over to our Swift Tutorials page for further reading.

Get started with Parse.com

First, Head over to Parse.com and sign up for your FREE account. You will see, in the top right corner of the page there are two buttons. One is sign up and the other is log in. Because we are starting this connect Swift to Parse.com tutorial as though you were a beginner, we want the signup option.

sign up to parse

You will then be presented with a form for you to sign up. Another great thing is that they allow you to signup using your Facebook, Github or Google account. Go ahead and signup with whatever method you want. Then the real fun for connecting your Swift based iOS Application to Parse.com can begin. So, once you have signed up the next form is about the app you want to create. We are going to call this App testData and in the Company Type drop-down selection we want to select Individual Developer.

parse connect swift application

Next, Click the big blue button start using Parse. That’s it. Your backend server for your app has been created. Pretty simple right, and awesome!.

Our next step is to create a new single view application in Xcode 6 and get some vital app data from parse. in order to connect your swift application to the parse.com service you will need an Application ID and Client ID. We will discuss this a littler further down.

Set up your Xcode Project

You will need to create a new single view application and make sure that Swift is selected for the language.

Once the Application is created, click on your Project and go to “Build Phrases”.
In the option “Link Binary With Libraries” you will have to add these Frameworks to use Parse.

  • AudioToolbox.framework
  • Foundation.framework
  • CoreGraphics.framework
  • CoreLocation.framework
  • libz.dylib
  • MobileCoreServices.framework
  • QuartzCore.framework
  • Security.framework
  • StoreKit.framework
  • SystemConfiguration.framework

Add the Parse.com iOS SDK to your project

Next we need to get the Parse SDK from their website. Go to: https://www.parse.com/downloads/ios/parse-library/latest and your download will start. Once that has downloaded and you have uncompressed it, drag the folder into your project navigator area of Xcode.

You will get a Dialogue that will look like this:

swift add parse ios sdk to xcode 6

You will need to check the box that says copy items if needed and then click Finish.

The next thing we need to do to connect our Swift app to parse.com is create a bridging header. To do this you need to create a new File (File -> New -> File) of type Objective-C File. Call this whatever you like. Here I have just called it testDataCustom. You will see another Dialogue that looks like this:

swift create parse bridging header

Click yes.

Now it will add some new files to your project. Click on the File: testData-Bridging-Header.h. You should see this:


//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

Underneath this comment code we need to add an #import so that our project knows to use the Parse iOS SDK. To do this we simply add a line into this file, like so:


#import 

That is now your Xcode project set up and ready to go. We now need to get some security keys from Parse, as mentioned earlier and add a few lines of code so that we can save data to the Parse service.

Using Swift to connect to Parse.com

Go back to the Parse.com log in area and select the Settings from the navigation pane that goes the full length of the page.

parse com navigation

On this page, down the left hand side you will see another menu structure. We need to click the Keys link.

parse com application keys

You will then be shown quite a few different application keys. The ones we want are the Application ID and the Client Key.

With these, we now need to go to the AppDelegate.swift in Xcode and change this function:


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

to this code:


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        
        Parse.setApplicationId(“your_application_key”, clientKey: “your_client_key”)
        
        // Override point for customization after application launch.
        return true
    }

Replace your_application_key and your_client_key with the keys that we just got from the Parse website.

If you have come to this tutorial as directed from this tutorial: Swift: Create user sign up based app with Parse.com using PFUser now is the time to go back

Also, in the same function, just below the code we have just added in. Add:


var object = PFObject(className: "testDataClass")
object.addObject("iOSBlog", forKey: "websiteUrl")
object.addObject("Five", forKey: "websiteRating")
object.save()

The official documentation says to use saveInBackground() as the last line there however I had a few problems with that and after a quick Google I found the solution to be just save().

Your entire function should now look like this:


 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
        
        Parse.setApplicationId("your_application_key", clientKey: "your_client_key")
        
        var object = PFObject(className: "testDataClass")
        object.addObject("iOSBlog", forKey: "websiteUrl")
        object.addObject("Five", forKey: "websiteRating")
        object.save()
        
        // Override point for customization after application launch.
        return true
    }

That’s it. You’re now done and have connected your Swift Application to the Parse.com Service.

Check the data

Go back to Parse.com and click the Core menu option on the top navigation pane.

parse com core menu

and you should see the data:

swift parse core data

Thank you. I hope you enjoyed this tutorial. Please leave any comments and queries in the comments section below an stay tuned for more tutorials.

Download the Source Files

[socialRansom link=”https://github.com/iOS-Blog/ConnectSwift-Parse/archive/master.zip”]

having issues?

We have a Questions and Answer section where you can ask your iOS Development questions to thousands of iOS Developers.

Ask Question

FREE Download!

Get your FREE Swift 2 Cheat Sheet and quick reference guide PDF download when you sign up to SwiftMonthly


Sharing is caring

If you enjoyed this tutorial, please help us and others by sharing using one of the social media buttons below.


iOS-Blog Admin Team

Written by:

We're here to help.

Comments

comments