I'm a little confused by whether Core Data generates primitive accessors for NSManagedObject subclasses in the form setPrimitiveAttributeName:, as compared to the form setPrimitiveValue: forKey:, which it seems to do consistently.
The source of my confusion is that I have used the modeling tool (XCode 4) to generate NSManagedSubclasses for two of my entities, which, as far as I can tell, share the same metadata settings, yet one subclass recognizes the setPrimitiveAttributeName 开发者_JAVA百科form, whereas the other doesn't (it gives me a "method not found" compiler warning).
So, what is the expectation? If I open up a new project, create one entity with one attribute, and use the modeling tool to generate the necessary NSManagedObject subclass code, should I expect it to auto-generate the more efficient form of the primitive accessor or not?
I've been running into a similar problem. While the runtime generates the primitive accessors, Xcode 4 does not generate the declared properties for primitives, you have to do this yourself in the subclass, per the docs.
I personally create a category for every Entity and always put my custom code in there, that way I can regenerate the MOs whenever I want and not have to copy and paste.
You can do this in a category, the interface has this:
@property (nonatomic, retain) NSDate * primitiveLastUsed;
And the implementation has this:
@dynamic primitiveLastUsed;
Pretty slick, makes regenerating MOs from Xcode painless.
精彩评论