Reputation: 63
I am having some problems with some old sample code when using it with Xcode 4.5.
In my code I have the following property defined
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
Then I have the following accessor 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 multiple errors as it cannot 'see' _managedObjectModel
. If I change the name of the accessor from managedObjectModel
to managedObjectModel2
, everything works fine. I guess that the issue is related to Xcode 4.5
automatic property synthesizing, but I don't know what I should do to avoid the issue. Any suggestions?
Upvotes: 6
Views: 842
Reputation: 57168
Clang won't automatically synthesize an instance variable for you if it doesn't have any methods to generate. In this case, you've asked for a readonly property, so there's no setter, and you've providing the getter. You can just @synthesize managedObjectModel=_managedObjectModel
or just declare the instance variable yourself.
Upvotes: 12