What I want to do is cause another save anytime saveInBackgroundWithBlock is called in my app. Im doing this to create a "log" of everything that changes and who changed it. I looked into the PFObject.h but I am not sure how to properly write this in Obj-C or where else/how I could do this other than going through and adding it to every single instance. Is this a good way to do it? Or should I stick it out and use the harder way?
- (void)saveInBackgroundWithBlock:(nullable PFBooleanResultBlock)block;
you have multiple ways in order to achieve this kind of functionality:
@interface ParseUtils : NSObject
+ (void)saveParseObject:(PFObject *)object block:(PFBooleanResultBlock)block;
@end
@implementation ParseUtils
+ (void)saveParseObject:(PFObject *)object block:(PFBooleanResultBlock)block {
// if the object is nil or it was not changed return
if (!object || !object.isDirty) return;
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
// if no error occured
if (!error){
// HERE YOU SHOULD CALL YOUR ADDITIONAL SAVE...
}
// handle the callback to the calling class
if (block){
block(succeeded,error);
}
}];
}
@end
Another option is to do the same but with singleton (if you created some REST Client singleton for your project)
Another nice option is to create category on top of the PFObject and there to create a method which do exactly the same like the method that of the util
There are more options but i think that it's enough.. if you want to do it as quick as possible use the utilities. if you want to do it with best architecture then go with the category.