-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make awakeFromInsert useful again #174
Comments
I think |
@jamesmoschou @mackross hey there, hope you are doing great!. I've been checking this ticket, and there's a catch to it. 'awakeFromInsert' is called when a NSManagedObject is first inserted into a NSManagedObjectContext. This means that a MO will have its 'awakeFromInsert' method called, at least, twice:
Without using another structure to hold metadata (which i'd love to avoid!), this scenario translates directly into 'awakeFromRemoteInsert' being called first, and 'awakeFromLocalInsert' afterwards, for a remote insertion. Assuming that the code you add to those methods (in your SPManagedObject subclass) takes that into consideration, it shouldn't be a problem. Just wanted to ask you: would this represent a problem for your use case? Thanks in advance!! |
It should call awakeFromLocalInsert only the second call: when the worker MOC is saved, and the MO is 'moved' to the writer MOC. I think before then the object is really still in Simperium's hands. |
@mackross implemented!. Thanks for your feedback! |
yay |
The awakeFromInsert method is typically used to initialize managed objects with default "baseline" values the first time they are inserted into any managed object context. For Simperium objects, it can no longer be assumed that this method will be invoked only once in the object's lifetime, since the object may exist across multiple clients.
I'm wondering if it is possible to add a method to SPManagedObject in the same vein as
-[UIViewController isMovingFromParentViewController]
that can be queried from within awakeFromInsert to determine if it is actually being created for the first time, or just synced from another device.Something like:
Alternatively Simperium could just provide another hook such as
-[SPManagedObject awakeFromLocalInsert]
.The text was updated successfully, but these errors were encountered: