Now that Xcode4 is publicly available I'm moving this question out of Apple's secret dev forum:
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?
I use Core Data custom managed classes and this was the procedure I followed in Xcode3:
Now, in Xcode4, I THINK this is how to do it, but I'm not sure because it generates different code:
The code it is generating is different for a number of reasons:
For example, Xcode3 would have generated this code in the HEADER file:
@interface SampleEntity (CoreDataGeneratedAccessors)
- (void)addChildObject:(Child *)value;
- (void)removeChildObject:(Child *)value;
- (void)addChild:(NSSet *)value;
- (void)removeChild:(NSSet *)value;
@end
Now, Xcode4 generates this code in the IMPLEMENTATION file:
@implementation SampleEntity
@dynamic children;
- (void)addChildObject:(Child *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"children"] addObject:value];
[self didChangeValueForKey:@"children" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
Can someone weigh in on why this is different? Xcode4 code sense does not like this new way of generating NSManagedObject subclasses.
Short answer: Don't use Xcode's code generation. Use mogenerator and enjoy an easier life.
As for the why, it is hard to say. I have never been a fan of the way that Xcode generates the Core Data subclasses and would not recommend them. We could guess as to why they did the things they have done but based on other issues with Xcode4 and Core Data I would chalk it up to "not ready" or "not fully tested".
File a radar if you would like to continue to use Xcode code generator.
It looks like all Xcode4 has done is make explicit what the @dynanmic directive makes implicit. The generated code looks exactly like that generated by Xcode3 when you asked it to generate accessors for a particular attribute (to the clipboard.)
I'm not sure why they decided to do it that way. Possibly they thought it would make it easier for people to create custom accessors if they just gave them the full basic accessor.
It shouldn't be that hard for someone to shoehorn MOGenerator into Xcode4. Hint, hint. Anyone? Come on guys! Anyone? Bueller?
Sigh, looks like it me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With