What is the sourcery going on here that makes it so I don't need to declare managedObjectContext as an ivar?? Where does __managedObjectContext
exist? What is with the double-underscore prefix?
Header
@interface CAHistoryController : NSObject {}
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@end
Implementation
@implementation EBHistoryController
@synthesize managedObjectContext=__managedObjectContext;
- (NSManagedObjectContext *)managedObjectContext
{
if (__managedObjectContext != nil)
{
return __managedObjectContext;
}
// ...etc
}
@synthesize grew the ability to automatically synthesize the associated storage in a relatively recent compiler release (actually, not so recent though the simulator initially didn't support this pattern).
@synthesize without the =<somename> part would generate an ivar with the same name as the property name. When you do =<somename>, you tell it to make an ivar with a different name.
来源:https://stackoverflow.com/questions/6837584/why-dont-i-need-an-ivar-for-this-core-data-property