mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-12 04:10:36 +01:00
How can I make update with mainContext? #50
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Koshub on GitHub (Apr 24, 2016).
Due the CoreData cache sometimes I have to call
refreshAndMergeto refetch objects from persistaten store. Do we have an API to update objects directly with main context, not with child of main?@JohnEstropia commented on GitHub (Apr 26, 2016):
CoreStore's main context is strictly readonly. This was designed for performance and data integrity.
I suggest you use ListMonitor or ObjectMonitor; objects managed by NSFetchedResultsController automatically gets refreshed.
@Koshub commented on GitHub (Apr 26, 2016):
Not sure your suggestion will resolve the issue. For example, I update
Projectentity and then after that immediately I try to load entity (FeedItem) with one-to-one relation of thatProjectand I receive unupdated object. Here is my code with comments where I have to put refresh calls:@JohnEstropia commented on GitHub (Apr 27, 2016):
This behaviour is
NSManagedObject's caching mechanism and beyond CoreStore's control(and thus the existence of
refreshAndMerge()andrefreshAsFault()methods.)Like I mentioned,
NSFetchedResultsControllerdoes this for free, but with the cost of constantly processing its objects. Otherwise, callingrefreshAndMerge()like how you did is correct.For the record, we can extend CoreStore to do this automatically all the time, but the performance cost may not be worth it.
@Koshub commented on GitHub (Apr 27, 2016):
Thank you for response. I can't use
NSFetchedResultsController. I think if I have the API to update objects with main context, not child, I will fetch always correct objects. I understand that you need child context to implement amazing transactions logic. Also I understand that I can use main context through fetched managed objects. Although I think you have the other reasons to make main context readonly I will be very happy if you try to provide some API to interact directly with main context. Thank you for your time and excellent Pod library.@JohnEstropia commented on GitHub (Apr 28, 2016):
Allowing updates to the main context objects means two things:
So sorry, I prefer the main context the way it is. IMO it's a small price to pay for all the safety and guarantees that CoreStore offers.
@Koshub commented on GitHub (Apr 28, 2016):
I see. I understand all these things. You are right. Thank you.