NSManagedObjectContext category
Closed this issue · 4 comments
buh commented
What do you think about this category? https://gist.github.com/buh/6643457
jksk commented
- Using
[NSManagedObjectContext context]
instead of[NSManagedObjectContext mainContext]
requires you to know that you're currently in the main thread. It means moving information from being explicit to being implicit, which decreases readability. While boilerplate Core Data code is too verbose (hence, this lib), I do not believe writing less is always better. Readability is more important. - Often, you want to call
[NSManagedObjectContext mainContext]
and[NSManagedObjectContext backgroundContext]
from different threads (in fact, I often call bothmainContext
andbackgroundContext
from the same method). The point of theperformBlock
method is that you can use managed contexts, which are thread safe, to manipulate managed objects, which are not thread safe, from wherever you are working. - Contexts do not belong to threads – this is the old confinement pattern. Coupling a context to a thread is misleading (even though it works).
buh commented
Thank you, Jesper, for your detailed comment! And I agree with you that readablity more important then shortness.
jksk commented
Not a problem, Alexey. Hope I could be of some help.
buh commented
Yes, of course, thanks again. I decided to remove a category in the project and explain team that it would be better.