1
votes

I had an original data model that was used to create NSManagedObject subclasses. I have now added custom code to these subclasses.

If you add new attributes to an existing entity, is there an easy way within Xcode 4.1/4.2 to update/add the new attributes to the existing classes.

The only way I can see at the moment is to create new subclasses then copy and paste the custom code, although this feels like it could be error prone.

I am in development at the moment, so I don't really care so much for the upgrade requirements of the data stores. Just the coding shortcuts.

Cheers.

1
checkout mogenerator. Does everything you want and more. Seriously, it's awesome and will save you a lot of time. - Rog

1 Answers

4
votes

Here is what I do for this case. You have to do it only once, with no more work required for future changes to the data model.

I create separate .h and .m files for my NSModeledObject subclasses with a category. For an entity called, say, "Event", it would look like Event+Helper.h and start like this:

#import "Event.h"
@interface Event (Helper)
// declare your public methods
@end

Now, when you generate the new subclasses from the model, all of these will still work.