NSManagedObject *newManagedObject =
;
is completely non-intuitive for me. Although the entity description is used in the process of inserting a new managed object, there's no way you can claim it's the primary object for that action.
I may be wrong, but I think it was this way in EOF, too. Anyway, the nice thing about having a dynamic language like Objective-C that supports categories is that you don't have to live with things that don't fit your particular way of thinking.
To me, the logical place for a method that inserts a new managed object into a managed object context, would be an instance method on the context, though I could also see an argument for it being a factory method on the managed object as well.
When I'm writing my own Core Data apps, I use this category:
NSManagedObjectContext-insert.h
NSManagedObjectContext-insert.m
This very short little category allows me to insert new objects into a context by simply doing this:
;
Which personally, I find a lot easier to remember than the first one.
0 komentar:
Posting Komentar