Browsing Parse Local Datastore for iOS

This post will walk through how you can view data in the Parse Local Datastore when running in the iOS simulator.

The Parse Local Datastore allows data to be stored locally on an iOS device when a network connection is unavailable, without using Core Data. It can be easily synchronized with the Parse data stored remotely in the backend when a network connection becomes available.

If you are running on the simulator you may want to browse the data stored locally, just like you can do with Core Data and with the Parse Data Browser for backend data. Since the Parse local data is stored in SQLite, you can use any suitable SQL browser. I use DB Browser for SQLite which is available here.

You need to know where to look for the data, so I’ll demonstrate using Swift.

Add the following code in your didFinishLaunchingWithOptions method of AppDelegate.

Run your app and in the console you’ll see the location of the simulator, such as:

Home directory: /Users/larrymacfadyen/Library/Developer/CoreSimulator/Devices/CF5AF467-B1AF-4749-98CF-7B9D7FEB695F/data/Containers/Data/Application/E27CC4A8-F33B-4687-8990-DD2A5B198E23

Open Finder, and select Go > Go To Folder, then paste the location from your console into the text box and click Go. In the folder you should see the following directories:

  • Documents
  • Library
  • tmp

You need to look in the directory Library\Private Documents\Parse, where you’ll see a file called ParseOfflineStore. Here is my Parse directory.

Screen Shot 2015-09-17 at 1.05.09 PM

Open this file with your SQL browser of choice, and you will be able to see the objects you’ve stored using the Parse Local Datastore.

I defined a Book subclass of PFObject. This is the Book class.

With my test app, I’ve stored one Book object in the local datastore. It has a title=”Swift 2.0″ and author=”Apple”. This is what the data looks like in the SQL browser.

Screen Shot 2015-09-17 at 1.09.04 PM

This is different than what you see if the data is stored in the Parse backend, and it is also different than what you’ll see looking at your Core Data SQLite database. Parse has added the record with _Pin by default, and there is the one Book record stored by my app.

One notable aspect of storage using Local Datastore is that the usual objectId for a Parse object does not have a value. This is only populated once you save it to the backend.

The data is stored as JSON, so you need to open up the json column to see the data that has been stored. For the one Book object, here is what it looks like.Screen Shot 2015-09-17 at 1.12.14 PMYou can see the values stored corresponding to the Book fields of author and title. Other data that Parse needs is also stored in the same column so that when it is synchronized with the backend the required data for built-in columns is available.

You can read more about the Parse Local Datastore on the Parse website.

Leave a Comment: