In my project I have two NSManageObjects
(Core Data generated). For both objects I have created a category with an instance method called containsToday
.
The problem is that only the method for the object ListElement
works. While calling the method for the object NamedRange
I get (same method as class method works):
-[NSManagedObject containsToday]: unrecognized selector sent to instance ...
Here is some code:
ListElement:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class ListImage, TLList;
@interface ListElement : NSManagedObject
@property (nonatomic, retain) NSString * agn;
@property (nonatomic, retain) NSString * aid;
@property (nonatomic, retain) NSString * date;
@property (nonatomic, retain) NSString * iid;
@property (nonatomic, retain) NSNumber * indx;
@property (nonatomic, retain) NSNumber * mark;
@property (nonatomic, retain) NSString * oid;
@property (nonatomic, retain) NSString * tcd;
@property (nonatomic, retain) NSString * ted;
@property (nonatomic, retain) NSNumber * cxl;
@property (nonatomic, retain) NSString * oti;
@property (nonatomic, retain) ListImage *listImage;
@property (nonatomic, retain) TLList *tlList;
@end
NamedRange:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface NamedRange : NSManagedObject
@property (nonatomic, retain) NSString * tid;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * sta;
@property (nonatomic, retain) NSString * end;
@end
ListElement (Additions):
#import "ListElement.h"
@interface ListElement (Additions)
- (BOOL) containsToday;
@end
NamedRange (Additions):
#import "NamedRange.h"
@interface NamedRange (Additions)
#warning TODO - why does this not work as instance method (for ListElement it works)?
+ (BOOL) containsToday:(NamedRange*)nr;
- (BOOL) containsToday;
@end
You probably haven't set the Entity Class in the data model correctly. The message indicates that it's attempting to call the method on an object of class NSManagedObject
, not an instance of your derived class.
In XCode, open up your data model, select the ListElement entity, then open the Data Model Inspector on the right hand side (in the Utilities bar) and check that the Entity Class is correct. If I'm correct, I think you'll find it's currently still set to NSManagedObject.