I am using core-data to add/delete 'Items' (NSManagedObject) to the model.
However, I am receiving the error in the title:
Code: Failed to call designated initializer on NSManagedObject class 'Item' I would really appreciate it if you could tell me where I am going wrong. I presume that the problem is to do with initialising Item.
RootViewController.m
- (void)AddNew {
CDManager *manager = [[CDManager alloc] initWithManagedObjectContext:[self managedObjectContext] andDelegate:self];
[manager addNewObject:[Item itemWithDescription:@"testing" dateSet:[NSDate date] fullfillBy:[NSDate date]]];
[manager release];
}
CDManager.m
- (id) initWithManagedObjectContext:(NSManagedObjectContext *)context andDelegate:(id<CDManagerDelegateProtocol>)delegate {
if ((self = [super init])) {
[self setDelegate:delegate];
[self setContext:context];
[self setItems:[[NSMutableArray alloc] init]];
[self updateItems];
}
return self;
}
- (void)addNewObject:(Item *)item {
NSManagedObjectContext *context = _context;
Item *items = [NSEntityDescription
insertNewObjectForEntityForName:@"Item"
inManagedObjectContext:_context];
[items setDateSet:[item dateSet]];
[items setDateToFullfill:[item dateToFullfill]];
[items setItemDescription:[item itemDescription]];
NSError *error;
if (![context save:&error]) {
NSLog(@"Couldn't save due to : %@", [error localizedDescription]);
}
[_delegate manager:self didAddNewItem:items];
[self update];
}
Item.m
static Item *shared = nil;
@implementation Item
......
+ (Item *)itemWithDescription:(NSString *)d dateSet:(NSDate *)date fullfillBy:(NSDate *)dates {
@synchronized(shared) {
if (!shared || shared == NULL) {
shared = [[Item alloc] init];
}
[shared setItemDescription:d];
[shared setDateSet:date];
[shared setDateToFullfill:dates];
return shared;
}
}