Lucas Bicca Karsburg
Lucas Bicca Karsburg

Reputation: 85

Method requires Pinning enabled

I'm trying to retrieve local datastore in swift Parse SDK the following way:

let query = PFQuery(className: "Cliente")
        query.fromLocalDatastore()
        do{
            object = try query.getFirstObject()
        }
        catch{
            return nil
        }

But when fromLocalDatastore() is called, in saw the follow exception:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Method requires Pinning enabled.'

In my AppDelegate, I'm calling Parse.enableLocalDatastore() before Parse configuration, like that:

Parse.enableLocalDatastore()
        let configuration = ParseClientConfiguration{
            $0.applicationId = "FF6itU7EzyH7dN10IL2KERRddpC7HYZUdTIA7HYV"
            $0.clientKey = "eQLh9J92OKMydnflk5VNFOVZnlkzLvCgVKQ6QtLr"
            //$0.server = ""
        }

        Parse.initializeWithConfiguration(configuration)

In some places, I saw suggestions to put $0.localDatastoreEnabled = true inside ParseClientConfiguration but it didn't work too.

And also, I can't to do that: configuration.localDatastoreEnabled = true because it is a get-only.

Have you another suggestions?

Upvotes: 3

Views: 406

Answers (1)

Ran Hassid
Ran Hassid

Reputation: 2788

in order to use local data store you need to do 2 things:

  1. set localDatastoreEnabled to true in your configuration.
  2. In order to fetch from local data store you need to pin it first to the local data store. So let's assume you have an object or list of objects that was fetched from the server or created manually in code. After you have the object in your code you need to write the following in order to pin in to the local data store (from Parse docs):

    let gameScore = PFObject(className:"GameScore")
    gameScore["score"] = 1337
    gameScore["playerName"] = "Sean Plott"
    gameScore["cheatMode"] = false
    gameScore.pinInBackground()

the pinInBackground() method will pin this object to the local data store and after you pin it you can then get it from the local data store via your code.

Upvotes: 2

Related Questions