Cannot override getter property with Xcode 4.5

I am having some problems with some old code example when using it with Xcode 4.5.

In my code, I defined the following property

@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; 

Then I have the following access method:

 - (NSManagedObjectModel *)managedObjectModel { if (_managedObjectModel != nil) { return _managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyPrototype" withExtension:@"momd"]; _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return _managedObjectModel; } 

The problem is that Xcode throws some errors because it cannot "see" _managedObjectModel . If I changed the name of the accessor from managedObjectModel to managedObjectModel2 , everything will be fine. I suppose the problem is with synthesizing the properties of Xcode 4.5 , but I don't know what I should do to avoid the problem. Any suggestions?

+6
source share
1 answer

Clang will not automatically synthesize an instance variable for you if it does not have methods to generate. In this case, you are requesting the readonly property, so there is no setter, and you are providing getter. You can simply @synthesize managedObjectModel=_managedObjectModel or simply declare the instance variable yourself.

+12
source

All Articles