Reputation: 2666
I am trying to update an array of PFObjects
. In my understanding, fetchAll()
(in its asynchronous derivations) is the correct method to update all the objects, as fetchAllIfNeeded()
will only update the PFObjects
that have no data associated with them yet. However each time fetchAll()
is executed, the entire list of PFObjects
is downloaded again, whether or not any change has been made. For example, if I have a list of posts, and I would like to check if any edits to the posts has been made, in every case all the posts in their entirety, (text, pictures and so on) will be downloaded, regardless of whether the text of one post was simply edited or even if there were any edits at all. There is a big difference in data consumption in downloading the text for one attribute of a PFObject
and downloading a whole array of them, many including pictures, and so I would like to find a method that will only download the changes. Is this possible?
In addition, if this is possible, is there a way that I could get a list of the PFObjects
that needed updating? i.e., if posts 4 and 12 needed updating out of an array of 20, how could I know this?
Thanks.
Upvotes: 1
Views: 275
Reputation: 114974
fetchAll does as it's name implies - fetches all objects. You can use a PFQuery against the updatedAt column to retrieve objects that have been updated since a certain date/time. You will need to keep track of your last update date/time locally, say using NSUserDefaults -
let query=PFQuery.queryWithclassName("MyClass")
let defaults=NSUserDefaults.standardUserDefaults()
if let lastUpdateDate=defaults.objectForKey("lastUpdateDate") as? NSDate {
q.whereKey("updatedAt",greaterThan:lastUpdateDate)
}
q.findObjectsInBackgroundWithBlock({(objects:[AnyObject]!, error: NSError!) in
if(error == nil) {
defaults.setObject(NSDate(),forKey:"lastUpdateDate")
for object in objects {
...
}
} else {
//Do something with error
}
})
Upvotes: 1