Why don't I need an ivar for this Core Data property?

眉间皱痕 提交于 2019-12-08 07:45:02

问题


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
}

回答1:


@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).




回答2:


@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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!