开发者

Updating NSManagedObject subclass after updating data model

开发者 https://www.devze.com 2023-04-12 04:34 出处:网络
I had an original data model that was used to create NSManagedObject subclasses. I have now added custom code to these subclasses.

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 entit开发者_StackOverflow社区y, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号