Can I add a custom method to Core Data-generated classes?

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-04-29T21:37:52Z Indexed on 2010/04/30 19:07 UTC
Read the original article Hit count: 160

Filed under:
|
|

I've got a couple of Core Data-generated class files that I'd like to add custom methods to. I don't need to add any instance variables. How can I do this?

I tried adding a category of methods:

// ContactMethods.h (my category on Core Data-generated "Contact" class)
#import "Contact.h"
@interface Contact (ContactMethods)
-(NSString*)displayName;
@end
...
// ContactMethods.m
#import "ContactMethods.h"
@implementation Contact (ContactMethods)
-(NSString*)displayName {
    return @"Some Name"; // this is test code
    }
@end

This doesn't work, though. I get a compiler message that "-NSManagedObject may not respond to 'displayName' " and sure enough, when I run the app, I don't get "Some Name" where I should be seeing it.

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about core-data