Source

tdd_ios_kiwi / code / TaskList / TaskList / Task+CRUD.m

//
//  Task+CRUD.m
//  TaskList
//
//  Created by Allan Davis on 11/1/12.
//  Copyright (c) 2012 Cajun Code. All rights reserved.
//

#import "Task+CRUD.h"

@implementation Task (CRUD)

+ (NSFetchRequest *) createFetchRequestWithContext: (NSManagedObjectContext *)context{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription
                                   entityForName:@"Task" inManagedObjectContext:context];
    [fetchRequest setEntity:entity];
    return fetchRequest;
}
+ (NSArray *) allTaskFromContext:(NSManagedObjectContext *)context{
    NSFetchRequest *fetchRequest = [self createFetchRequestWithContext:context];
    NSError *error;
    return [context executeFetchRequest:fetchRequest error:&error];
    
}
+ (Task *) taskWithName:(NSString*)name fromContext:(NSManagedObjectContext *)context{
    Task *task = [NSEntityDescription insertNewObjectForEntityForName:@"Trim" inManagedObjectContext:context];
    task.name = name;
    NSError *error = nil;
    [context save:&error];
    return task;
}

- (void)save:(NSError *)error{
    [self.managedObjectContext save: &error];
}

- (void)deleteTask{
    [self.managedObjectContext delete:self];
}

@end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.