Help help help help!


#1

[quote]2012-10-22 18:51:27.793 MyPrince2[1598:c07] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: 'keypath dateCReated not found in entity '
*** First throw call stack:
(0x13ab022 0x119acd6 0x357d9 0x3543e 0x351f0 0x34fc3 0x34619 0x340b0 0x3345d 0x312fd 0x35e7 0x2f05 0x2b58 0x5442 0x4db06b 0x4dd862 0x38b66d 0x38b167 0x520b 0x3c638f 0x3c65eb 0x3d6ff1 0x3d785f 0x3d521f 0x3ebdf1 0x3ebe0d 0x3ebea9 0x32a6f5 0x32a73c 0x259f 0x2fb386 0x2fc274 0x30b183 0x30bc38 0x2ff634 0x1f7fef5 0x137f195 0x12e3ff2 0x12e28da 0x12e1d84 0x12e1c9b 0x2fbc65 0x2fd626 0x229d 0x2205)
terminate called throwing an exception[/quote]

[code]#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class PR2Processes;
@class PR2ProjectProcess;
@class PR2ProjectName;

@interface PR2ProjectStore : NSObject
{
NSMutableArray *allprojectname;
NSMutableArray *allprocesses;

NSManagedObjectContext * context ;
NSManagedObjectModel * model;

}

+(PR2ProjectStore *)sharedStore;

-(NSArray *)newProcesses;

-(NSArray *) allprojectname;
-(NSArray *) allprocesses;

-(PR2ProjectProcess *) createProcess;
-(PR2ProjectName *) createName;

-(void) removeProcess:(PR2ProjectProcess *) pr;
-(void) removeProjectName: (PR2ProjectName *) pn;

-(void) loadAllProjectname;

-(BOOL)isChange;

-(NSString *) FilePathArchive;

@end
[/code]

[code]#import “PR2ProjectStore.h”
#import “PR2Processes.h”
#import “PR2ProjectName.h”
#import “PR2ProjectProcess.h”

@implementation PR2ProjectStore

+(PR2ProjectStore *)sharedStore
{
static PR2ProjectStore *sharedStore = nil;

if (!sharedStore) {
    
    sharedStore = [[super allocWithZone:nil] init];
}

return sharedStore;

}

+(id)allocWithZone:(NSZone *)zone
{
return [self sharedStore];
}

-(id)init
{
self = [super init];

if (self) {
    
    model = [NSManagedObjectModel mergedModelFromBundles:nil];
    
    NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
    
    
    NSString *path = [self FilePathArchive];
    NSURL *storeURL = [NSURL fileURLWithPath:path];
    
    NSError *error = nil;
    
    if (![psc addPersistentStoreWithType:NSSQLiteStoreType
                           configuration:nil
                                     URL:storeURL
                                 options:nil
                                   error:&error]) {
        
        
        [NSException raise:@"Open Failed"
                    format:@"Reason : %@", [error localizedDescription]];
    }
    
    
    
    context = [[NSManagedObjectContext alloc] init];
    [context setPersistentStoreCoordinator:psc];
    
    // we dont need the undo right now
    
    [context setUndoManager:nil];
    
    
    [self loadAllProjectname];
    
}

return self;

}

-(NSArray *)newProcesses
{
PR2Processes * pro = [[PR2Processes alloc] init];
[pro createProcess];

return [pro processes];

}

#pragma mark - return projectname and proccess

-(NSArray *) allprojectname
{
return allprojectname;
}

-(NSArray *) allprocesses
{
return allprocesses;
}

#pragma mark - object creation

-(PR2ProjectProcess *)createProcess
{
PR2ProjectProcess *pr = [NSEntityDescription insertNewObjectForEntityForName:@"PR2ProjectProcess"
inManagedObjectContext:context];

[allprocesses addObject:pr];

return pr;

}

-(PR2ProjectName *) createName
{
PR2ProjectName *pn = [NSEntityDescription insertNewObjectForEntityForName:@"PR2ProjectName"
inManagedObjectContext:context];

[allprojectname addObject:pn];


return pn;

}

-(BOOL)isChange
{
NSError *error = nil;

BOOL success = [context save:&error];

if (!success) {
    
    NSLog(@"Fail to Save - REASON : %@", [error localizedDescription] );
}


return success;

}

#pragma mark - delete object

-(void) removeProcess:(PR2ProjectProcess *)pr
{
[context deleteObject:pr];
[allprocesses removeObjectIdenticalTo:pr];
}

-(void) removeProjectName:(PR2ProjectName *)pn
{
[context deleteObject:pn];
[allprojectname removeObjectIdenticalTo:pn];

}

#pragma mark - Fetching items

-(void) loadAllProjectname
{
if (!allprojectname) {

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription  *projectName = [[model entitiesByName]
                                         objectForKey:@"PR2ProjectName"];
    
    [request setEntity:projectName];
    
    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"dateCReated"
                                                           ascending:YES];
    
    [request setSortDescriptors:[NSArray arrayWithObject:sort]];
    
    NSError *error = nil;
    
    NSArray *result = [context executeFetchRequest:request error:&error];
    
    if (!result) {
        
        [NSException raise:@"Fetch Failed"
                    format:@"Reason : %@", [error localizedDescription]];
    }
    
    allprojectname = [[NSMutableArray alloc] initWithArray:result];
}

}

-(NSString *) FilePathArchive
{
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];

return [documentDirectory stringByAppendingPathComponent:@"store.data"];

}
[/code]