I have already read up on @synthesize
and found some really great information on this question: What exactly does @synthesize do? and I understand the difference between an instance variable and a property, but in the code I inherited, my problem goes a little further than that and I would like to know what it does (or if it's necessary) in the following circumstance. If more code context is needed just ask.
// example.h
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
// example.m
@synthesize managedObjectContext = _managedObjectContext;
//... later on in example.m
- (NSManagedObjectContext *)managedObjectContext {
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
_managedObjectContext = [[NSManagedObjectContext alloc] init];
return _managedObjectContext;
}
So in the example from the linked answer MapView
and MapView1
were both defined in the .h
file whereas in my example, a pointer to _managedObjectContext
is never defined as far as I can tell after doing a global search. We're using it with the @synthesize
keyword as well as providing a concrete definiton of managedObjectContext
in the implementation file.
So my question is really 2:
- Is
@synthesize
even doing anything here? - Why does it still compile when
_managedObjectContext
isn't defined like in the other example question?