Using Parse with Swift and Xcode 6

Parse is a platform that offers many tools and one of the things it provides is a “service as a back-end”. Parse takes care of the implementation of the back-end so that developers can focus on building their apps while still leveraging the power of having data persistence in the cloud.


Long time reader, Lukas von Mateffy, shares this tutorial with you guys on how to use Parse in Swift.


When Apple announced Swift, they told us that their new programming language will still support Objective-C Code. Than means, we can still use the popular Frameworks like Parse etc.! If you don’t know what Parse is, check it out HERE.

For the Usage of Parse Features, Chris has already made a Tutorial in his Course.
Since the Methods are the same you can still work with the Methods you used before and you only have to change the Syntax.

In this Tutorial I will only cover how to import Parse Framework into your Swift Project and some Basics in how to use it. Alright, let’s get started!

Step 1: Setup Parse Backed

First of all you have to register a new Account at Parse.com.

Parse Site

Then it will prompt you to create a new Application. If you already have an Account, then you have to create one by yourself.

Parse Create an App

Enter the name of your Application and click “Create app”.

After that step, it will show you a List of your Application Keys. Keep these safe! With them you will access your Parse Data etc.! For the iOS App you will need the Application Key and the Client Key.

Parse App Keys

Now go to the Downloads Section in your Parse Backend. Then download the Parse iOS SDK.

Parse Download SDK

Step 2: Setup Xcode Project

Create a new Xcode Project and fill in your Information. It’s important that you select Swift as the programming language.

Parse New Xcode Swift Project

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

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

Parse Configure Project

Then you can simply drag the Parse.framework you downloaded before into your Project. It’s important to check “Copy Items if needed” when you drag over the File.

Add Parse Files

Step 3: Import Parse into Swift

Create a new File (File -> New -> File) of type Objective-C File.

Parse New Swift Class

Name it whatever you want, we’ll just call it “CustomClass”. It will prompt you if you would like to configure an Obj-C Bridging Header. Click “Yes.

Parse Configure Bridging Header

Now it will add two new Files to your Project. First the .m File with your the Name you specified for your class. Delete this File. The second File is called YourProjectName-Bridging-Header.h. and this File is our Key to success.

Parse Swift Xcode File Navigator

Add this code to the YourProjectName-Bridging-Header.h:

Step 4: Initialize Parse

Go into your AppDelegate.swift File and add this Code to your applicationDidFinishWithLaunching Method:

Parse.setApplicationId(“your_application_key”, clientKey: “your_client_key”)

Replace “your_application_key” and “your_client_key” with your own Keys and now you’re ready to use Parse.

To proof that it actually works, add this code to the same method and run the app.

Parse Inserted Data

If you then take a look at the Data Browser in your Parse Backend, you will see some new Objects added!

And that’s how you use Parse in Swift.

Lukas is a 14 year old Web and App Developer. Being a long time reader, he now wants to share his knowledge about developing apps for the iPhone, iPad and iPod Touch.

36 Comments

  1. Hello Chris! Thank you for the review. It’s very easy to follow but i got a problem when i tried to compile it.
    I got this error message on linker things. I already tried to add Bolts framework to the project but it doesn’t work.

    I got Parse ver 1.6.0 btw.

  2. I don’t get the dialog to create bridging header file. Only the CustomClass.m is created. I’m using Xcode 6.1.1 What am I doing wrong?

  3. May I know where to get this framework? After I downloaded parse SDK, it only contain bolts, parse, parsefacebookutills, parseui framework only. Thank you.

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

  4. Hey can you recommend a good resource for learning developing with parse and swift more in depth? I am trying to use the tutorial videos on parse’s website but it is in objective c and I am having trouble converting syntax. Specifically I was trying to implement simple login with username and password and I just keep getting a blank screen. Any tips or resources?
    Thanks!

  5. Hi Chris, I try to do this example but with the new version I don’t have the option saveInBackground. I have another options:

    – saveInBackgroundWithTarget(, selector: )
    – saveInBackgroundWithBlock( Void#>)

    I don’t know how to use this two options.

    Thanks

  6. hi, appear me this error or what is that thing … how can i fix it? ://Users/JoaoFernandes/Desktop/Captura de ecrã 2014-10-24, às 00.51.05.png

  7. when you use .addObject forKey: it adds the values as arrays rather than their real types. You should just use object[“favoriteFood”] = “banana” instead

  8. Im new to iphone dev. I went through the tutorial it all compiles correctly I never see the data show on the parse side of the deal. Can’t figure out what im doing wrong since it compiles!! Any pointers would be greatly appreciated!!

  9. I get these errors when running:

    Undefined symbols for architecture x86_64:
    “_OBJC_CLASS_$_BFExecutor”, referenced from:
    objc-class-ref in Parse(BFTask+Private.o)
    l_OBJC_$_CATEGORY_BFExecutor_$_Background in Parse(BFTask+Private.o)
    “_OBJC_CLASS_$_BFTask”, referenced from:
    objc-class-ref in Parse(PFObject.o)
    objc-class-ref in Parse(PFFile.o)
    objc-class-ref in Parse(PFNetworkCommandRunner.o)
    objc-class-ref in Parse(PFQuery.o)
    objc-class-ref in Parse(PFRetryingCommandRunner.o)
    objc-class-ref in Parse(PFTaskQueue.o)
    objc-class-ref in Parse(PFUser.o)

    “_OBJC_CLASS_$_BFTaskCompletionSource”, referenced from:
    objc-class-ref in Parse(PFObject.o)
    objc-class-ref in Parse(PFCommandCache.o)
    objc-class-ref in Parse(PFFile.o)
    objc-class-ref in Parse(PFNetworkCommandRunner.o)
    objc-class-ref in Parse(BFTask+Private.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

  10. That’s great. Thank you 🙂

    One small note… when I cut and paste the Parse.SetApplicationId line, it copied the italicised quotes which caused the code to fail to be parsed.

    I had the change the quote like this “ to a quote like this ”

    The difference is subtle and hard to spot.

    🙂

  11. At Step 4 there’s some Code that isn’t in a code box (syntax highlighting etc.).

    But thanks Chris for publishing this Tutorial! 😀

Leave a Comment

29 Shares
Share
Tweet
Pin
Share
Buffer