iOS 8.3+
Swift 1.2
Parse 1.7.2

2015/04/14 — Updated to cover Parse 1.7.2.

iOS Swift 1.2 + Parse.com / Tutorial — set up Xcode project (Part 1 of 3)

Managing your app data is not trivial, requiring skills, thought processes and time most app developers do not have.

So just how do you get data into your app? Protect and secure the data? Share data between the correct people? Manage data over time to ensure accuracy?

I think we’re all agreed, dealing with data from your app is not a trivial task, and if you want ot sleep soundly at night you’re going to need some expertise to back you up.

Fortunately there are several companies out there providing Mobile Backend As A Service (MBAAS) platforms which you can quickly plug into your app and that deliver all your data (and sometimes more) needs.

Key benefits of using a MBAAS platform

  • Server maintenance, security and uptime is managed by professionals
  • Ease of cross platform development
  • No upfront infrastructure costs
  • Pay only for usage — your bill only grows as your app becomes more successful
  • Improved performance — when compared to average self hosting

After spending 10 minutes on Google and 20 minutes wandering over several vendor sites I settled on Parse as the vendor that I am going to take for a spin. The documentation looks good, the prices look good (free to start), the range of features look excellent and the name occasionally pops up on mobile app development sites whcih gives me a some confidence.

There is a shopping list of all the links you might need at the end of this page.

Signing up to parse.com

Signing up to Parse could not be easier. Just your name, email address and the name of your app — no credit cards or addresses. You’ll also be asked to select the type of your company — select “Individual…” and the rest of the sign up process is circumvented. You’ll receive an obligatory welcome email containing links to blogs and documentation etc. The site contains a lot of functionality — you’ll need to spend some time on your own getting familiar with all the tools and features — I am not going to discuss the Parse website beyond creating a data class and loading it with some data.

Creating a data class and adding some data

Right. Let’s create a data class and add some data. FYI — A data class equates to a data table.

Step 1 — Add a class

Click the “Add a class” button. This presents a modal popup where you select the “type” of class and name your class. Select “Custom” and provide an appropriate class name. Remember — a “class” is analogous to a table name.

Step 2 — Add come columns

There are several columns already created and managed by the Parse system — we don’t need to worry about these columns right now.

  • ACL — provides for row level security permissions
  • createdAt — date/time row created — set by Parse system
  • objectID — unique ID of the “object” = “class + row”, set by the Parse system
  • updatedAt — date/time row last updated — set and managed by Parse system

Click the “+ Col” button. Another modal dialog will display — select type “String” and give your column a name. For the purposes of this tutorial I’ll create some simple geography type data columns — nameEnglish, nameLocal, capital, currencyCode. You’ll need to read the documentation if you want to learn about the other data types (or maybe in the future I’ll create another article).

Step 3 — Add some data

Make sure you add several rows of data — the more the merrier for when you get to display this in an app table view.

Keys and connecting your XCode project

Adding Parse to your XCode project is a 3 step process. Step 1 — add the required frameworks to your project. Step 2 — add the security keys to your app delegate. Step 3 — code. All simple stuff — let’s get started.

For this tutorial create a Single View application and remember to select Swift as the development language.

Step 1 — Frameworks

In all there are 13 frameworks and 2 libraries that need to be added to your XCode project.

Apple

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

Parse

  • Bolts.framework
  • Parse.framework
  • ParseCrashReporting.framework
  • ParseFacebookUtils.framework
  • ParseUI.framework

NB : Truth is that it is possible your project will not require all of these libraries. Right now I am not clear under which scenario each is required — with trial and error (or maybe a document somewhere) it should be possible to remove the frameworks that your project does not make use of. Which would be a good thing right!

So step 1 of step 1 is to download the Parse framework files and “drag” these files into your project.

Remembering to ensure the “copy items if needed” option is selected.

The remaining frameworks and libraries are already on your machine — they come with XCode. So all we need to do is tell XCode to include them. Within XCode click on the project title to view the project settings. On the General tab, at the bottom, you’ll see a section titled “Linked Frameworks and Libraries” — click the + button.

You need to add the following…

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

The final step in step 1 is to create an objective c bridging header file. (I have prepared one for you in the Git repository) The easist way to create a bridging header file for yourself is to add a NEW file to your project, selecting iOS > Header File.

It is CRITICAL that this file be named correctly — get this part wrong and the header will not work. The file name format = XCodeProjectName + “-Bridging-Header.h”. My project XCode project name = “ParseTutorial” so my header file name = “ParseTutorial-Bridging-Header.h”.

Edit the .h file and set the contents to…

Step 2 — Keys So now we are ready to add some security keys to our project. You will find the keys within the Settings \ Keys section of the parse web site. The two keys we require for iOS are the Application ID and the Client Key. These keys need to be added to the top of the project AppDelegate.swift file.

This is what the TOP of your AppDelegate.swift should look like — well with your keys.

That’s it! We are now set up. Before we move to the next stage — build the project to check that all is good with the world.

Okay. Time to actually write some code! See you in Part 2!

Links

Originally published at www.bizzi-body.com/blog on February 4, 2015.