Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update pinned PFObject in Parse Local Storage from Parse Cloud

By object.saveEventually(), I will be able to sync my data in local storage with the cloud in Parse.

But here is what I am confused about, in the doc, it declares:

When an object is pinned, every time you update it by fetching or saving new data, the copy in the local datastore will be updated automatically

But then, next example, few paragraphs away, unpins all objects then updates HighScores by pinning the new scores array with name HighScores

PFQuery *query = [PFQuery queryWithClassName:@"GameScore"];
[query orderByDescending:@"score"];

// Query for new results from the network
[[query findObjectsInBackground] continueWithSuccessBlock:^id(BFTask *task) {
  return [[PFObject unpinAllObjectsInBackgroundWithName:@"HighScores"] continueWithSuccessBlock:^id(BFTask *ignored) {
    // Cache the new results.
    NSArray *scores = task.result;
    return [PFObject pinAllInBackground:scores withName:@"HighScores"];
  }];
}];

Therefore, should I unpin all objects of HighScores in order to update existing scores in HighScores?

Will findObjectsInBackground automatically update any found object which is pinned? I am quite confused.

Thank you!

like image 374
donkey Avatar asked Jan 27 '15 11:01

donkey


1 Answers

I found out that both findObjectsInBackground and fetchAllInBackground will update any pinned object matching the objectId.

That is to say, when you create an object initially, it will not have an objectId, but you can still pin this object without successfully saving it. However, you can't find or fetch them until you successfully save it to the cloud. So in the code, you have to cherrypick these particular PFObjects out and update them some other ways or don't update them at all.

like image 176
donkey Avatar answered Oct 17 '22 00:10

donkey