Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 503
Lucas Bicca Karsburg Avatar asked Jun 17 '26 19:06

Lucas Bicca Karsburg


1 Answers

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.

like image 138
Ran Hassid Avatar answered Jun 20 '26 08:06

Ran Hassid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!