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.
Then it will prompt you to create a new Application. If you already have an Account, then you have to create one by yourself.
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.
Now go to the Downloads Section in your Parse Backend. Then download the Parse iOS 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.
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.
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.
Step 3: Import Parse into Swift
Create a new File (File -> New -> File) of type Objective-C File.
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.
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.
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.
var object = PFObject(className: "TestClass")
object.addObject("Banana", forKey: "favoriteFood")
object.addObject("Chocolate", forKey: "favoriteIceCream")
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.