While Parse Cloud Code provides an on-save hook that lets you perform custom actions on the backend when objects are saved, their iOS SDK doesn't have any similar hook for when objects are saved into the local datastore with -save(Eventually)*
methods.
I would like changes in data to drive my custom actions, such as update the application's UI, refreshing a table etc.. How could this be done? Are there any NSNotification
s that you could observe?
A lot would depend on if your local "afterSave" is dependent on confirmation of a save in the cloud or not. Consider the following two examples.
You can pinInBackgroundWithBlock and send a notification as well as save eventually. The notification would send right away unless there was an error pinning. Keep in mind that your saveEventually could still fail.
[myObject pinInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if( succeeded ){
[[NSNotificationCenter defaultCenter]postNotificationName:@"localBeforeSave" object:myObject];
[myObject saveEventually];
}
}];
Or you can just use a block to send a local notification once you can confirm that the save eventually completed.
[myObject saveEventually:^(BOOL succeeded, NSError *error) {
[[NSNotificationCenter defaultCenter]postNotificationName:@"localAfterSave" object:myObject];
}];