These are basic concepts in Objective-C, but here's a quick rundown:
Instance members are generally considered to be private, and you should kind of never access the instance members of other objects except through accessors. Hence the need for the
property declarations are like method definitions; @property (…, readonly) NSManagedObjectModel *managedObjectModel;
is basically the same as - (NSManagedObjectModel *)managedObjectModel;
, except for the fact that it enables dot-notation.
The category is used to hide these accessors from the users of the class (for whatever reason); hence the name PrivateCoreDataStack
. The category is the reason dot-notation works; if you remove it, it won't.
As for the names; method names and instance members name live in separate namespaces; meaning that they can have the same name; this is very handy, because it tells you that - (id)somePropery;
accesses id someProperty;
; or that @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
accesses NSManagedObjectContext *managedObjectContext
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…