title: How does the automatic property synthesize in xcode 4.4 work?
body: <p>I'm new to Objective-C and XCode, but I was happy to see that XCode 4.4 automatically synthesizes my properties for me, now. I figure this means that I no longer have to type out @synthesize for my properties, and that I get to access them using <code>self.propertyName = @&quot;hi&quot;;</code>, for example.</p>
  <p>I'm trying to re-write some example code so that I can understand it better, but this code implements a custom getter method. In the example code, the property is manually synthesized, as <code>@synthesize managedObjectContext = __managedObjectContext;</code>. The custom getter looks like this:</p>
  <pre><code>- (NSManagedObjectContext *)managedObjectContext {
      if (__managedObjectContext != nil) {
          return __managedObjectContext;
      }
      
      NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
      if (coordinator != nil) {
          __managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
          [__managedObjectContext setPersistentStoreCoordinator:coordinator];
      }
      
      return __managedObjectContext;
  }
  </code></pre>
  <p>In this person's code, I see he's just using his manually synthesized accessor to both get and set. I figured in my code, I could just replace the <code>__managedObjectContext</code> with <code>self.managedObjectContext</code>, but nope. If I do this, I get an error telling me that I am trying to assign to a <code>readonly</code> property. This makes sense, because that property is defined as readonly, by this other coder.</p>
  <pre><code>@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  </code></pre>
  <p>So, I figure something about how he's manually synthesizing his property means that if he uses that specified setter, it allows him to set a readonly property somehow.</p>
  <p>If I manually synthesize the property, like in the code I am referencing, everything goes back to working, but that's not making use of the new automatic synthesize. If I remove the <code>readonly</code>, I can set this property, as expected, but I feel like I'm not understanding why he has it as readonly, so I bet I'm breaking something there.</p>
  <p>So, am I misusing the new automatic synthesize? How do I set this using the setter, if the automatic synthesize is not creating it for me, because of readonly?</p>