How to properly Pin in Parse localDataStore?

413 views Asked by At

I have Parse.enableLocalDatastore() in my app delegate before Parse.setApplicationId

Then I have var newPosts = PFObject(className: "Post") as a global variable.

Then I want to get 1,000 latest objects from the "Post" table from localDataStore that I enabled earlier so I do this:

var getNewPosts = PFQuery(className: "Post")
getNewPosts.fromLocalDatastore()
getNewPosts.limit = 1000
getNewPosts.orderByDescending("createdAt")
getNewPosts.findObjectsInBackgroundWithBlock {
    (downloadedPosts, error) -> Void in
        if downloadedPosts != nil && error == nil {
            println(downloadedPosts) // I am getting table with no data
        }
    }

But I only get empty data rows. If I comment out the getNewPosts.fromLocalDatastore() line results are fine.

I understand that I am missing the critical Pinning step but not sure from Parse documentation hoe and where to implement it. Can you please help?

1

There are 1 answers

3
Mahendra On

You are getting no data.... reasons my be...

Wrong name of class (class names are case sensitive) Data is not there in local storage

Try synchronous version of findObject: method and pin: method.