title: Xcode4: Different code generated for custom core data managed objects
body: <p>Now that Xcode4 is publicly available I'm moving this question out of Apple's secret dev forum:</p>
  
  <p>Can someone explain why the code generated in the following procedure is different than in Xcode3? Is the code better or might this be a bug?</p>
  
  <p>I use Core Data custom managed classes and this was the procedure I followed in Xcode3:</p>
  
  <ol>
  <li>Go to the model editor</li>
  <li>Select the entity you wish to generate source code for</li>
  <li>Go to File->New->New Files</li>
  <li>Choose managedobject class (or whatever it was, I can't open xcode3 anymore to verify)</li>
  <li>Select entities you wish to generate (the previously selected entity in step 2 is checked off)</li>
  <li>Click Finish</li>
  </ol>
  
  <p>Now, in Xcode4, I THINK this is how to do it, but I'm not sure because it generates different code:</p>
  
  <ol>
  <li>Go to model editor</li>
  <li>Select entity</li>
  <li>Go to File->New->New File</li>
  <li>Choose "NSManagedObject subclass"</li>
  <li>Choose location and create.</li>
  </ol>
  
  <p>The code it is generating is different for a number of reasons:</p>
  
  <ol>
  <li>The generated code for adding and removing members of a set in the entity are no longer declared in the @interface, but instead @implementation. This causes code sense to fail detecting these methods.</li>
  <li>The same generated code for adding and removing objects is now fully defined, no longer autogenerated using CoreDataGeneratedAccessors</li>
  </ol>
  
  <p>For example, Xcode3 would have generated this code in the HEADER file:</p>
  
  <pre><code>@interface SampleEntity (CoreDataGeneratedAccessors)
  - (void)addChildObject:(Child *)value;
  - (void)removeChildObject:(Child *)value;
  - (void)addChild:(NSSet *)value;
  - (void)removeChild:(NSSet *)value;
  @end
  </code></pre>
  
  <p>Now, Xcode4 generates this code in the IMPLEMENTATION file:</p>
  
  <pre><code>@implementation SampleEntity
  @dynamic children;
  - (void)addChildObject:(Child *)value {    
      NSSet *changedObjects = [[NSSet alloc] initWithObjects:&amp;value count:1];
      [self willChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
      [[self primitiveValueForKey:@"children"] addObject:value];
      [self didChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
      [changedObjects release];
  }
  </code></pre>
  
  <p>Can someone weigh in on why this is different? Xcode4 code sense does not like this new way of generating NSManagedObject subclasses.</p>