This is tagged with iOS
, but I'm sure it could be useful for the other Parse SDKs as well. As you may know, Parse added the ability to create native PFObject
subclasses to the iOS
SDK not too long ago. This is a great addition for a number of reasons. Firstly, it allows compiler to check your code by creating dynamic properties for object attributes:
myObject[@"myAttribute"]
is converted to myObject.myAttribute
Secondly, and more important to this question, custom subclasses can have added functionality. For example, say I have created an alarm app that stores Alarm
objects on the Parse cloud. In my custom subclass, I can override the + (instancetype)object
, - (void)saveEventually
, and - (void)deleteEventually
methods so that the alarm
object can schedule/update/remove a UILocalNotification
for itself upon creation, modification, or deletion.
Here's where things get complicated and my actual question comes in. Say a user creates an alarm on one device (which uploads it to the cloud), and then syncs it automatically to another device. The second device obviously updates it's contents in the background with PFQuery
's - (BFTask *)findObjectsInBackground
and then calls - (BFTask *)fetchIfNecessaryInBackground
on each object to ensure that all of its substance is on the device. My question is: What method(s), if any, gets called when a PFObject
subclass is found/fetched from the Parse cloud database? For that matter, what about objects initialized from the local datastore?
Like I mentioned, overriding various methods works perfectly for objects that are created and managed on the device, but I am baffled as to how one would run custom code from within a new object that just arrived in memory from the local or remote datastore. Any thoughts or suggestions on how to handle this would be much appreciated. The Parse documentation does not cover such a case, so it may not even be best practice, but it seems to me that it should be. Anyway, thank you for your time and your insights.