Core Data - WBCoreDataAccess

I've created a data layer abstraction for some of my core data interactions. It works by abstracting the getting and deleting features of core data out, which allows me to focus on using the data not how I get the data
The .h file:

  
/*!

 @class CoreDataAccess

 @abstract This class provides a number of useful extensions to the NSManagedObject class

 @namespace model

 @updated 2010-08-12

 */
@interface CoreDataAccess : NSObject {

}

#pragma mark -
#pragma mark ManagedObjectContext accessors

+(void) setManagedObjectContext:(NSManagedObjectContext*)context;
+(NSManagedObjectContext*) getManagedObjectContext;

#pragma mark -
#pragma mark Retrieval Methods - without faulting

/*!
 @function This returns all records that exist for a table without faulting
 @param table - an NSString that presents a table in the database
 */
+(NSArray*) getRecordsWithoutFaultingForTable:(NSString*)table;

/*!
 @function This returns records that exist for a table based on a condition(s) without faulting
 @param table - an NSString that presents a table in the database
 @param predicate - A predicate which limits the number of records returned
 */
+(NSArray*) getRecordsWithoutFaultingForTable:(NSString *)table withPredicate:(NSPredicate *)prd;

/*!
 @function This returns records that exist for a table based on a condition(s) without faulting
 @param table - an NSString that presents a table in the database
 @param predicate - NSString representation of a predicate which limits the number of records returned
 */
+(NSArray*) getRecordsWithoutFaultingForTable:(NSString*)table WithStringPredicate:(NSString*)prd;

#pragma mark -
#pragma mark Retrieval Methods - With faulting

/*!
 @function This returns all records that exist for a table
 @param table - an NSString that presents a table in the database
 */
+(NSArray*) getRecordsForTable:(NSString*)table;

/*!
 @function This returns records that exist for a table based on a condition(s)
 @param table - an NSString that represents a table in the database
 @param predicate - A predicate which limits the number of records returned
 */
+(NSArray*) getRecordsForTable:(NSString *)table withPredicate:(NSPredicate *)prd;

/*!
 @function This returns records that exist for a table based on a condition(s)
 @param table - an NSString that represents a table in the database
 @param predicate - NSString representation of a predicate which limits the number of records returned
 */
+(NSArray*) getRecordsForTable:(NSString*)table WithStringPredicate:(NSString*)prd;

/*!
 @function This returns records that exist for a table based on a condition(s)
 @param table - an NSString that represents a table in the database
 @param top - NSNumber that determines how many records to return
 @param column - NSString that represents a column name
 @param ascending - Boolean to sort records in ascending or descending order
 */
+(NSArray*) getRecordsForTable:(NSString*)table Top:(NSNumber*)top OnColumn:(NSString*)column Ascending:(Boolean)order;


/*!
 @function This returns records that exist for a table based on a condition(s)
 @param table - an NSString that represents a table in the database
 @param column - NSString that represents a column name
 @param ascending - Boolean to sort records in ascending or descending order
 */
+(NSArray*) getRecordsForTable:(NSString*)table OnColumn:(NSString*)column Ascending:(Boolean)order;


#pragma mark -
#pragma mark Delete methods


/*!
 @function Deletes a managed object from the database
 @param object - Record to be deleted
 */
+(void) deleteRecord:(NSManagedObject *)object;

/*!
 @function Deletes all entries from database table
 @param table - an NSString that represents a table in the database
 */
+(void) deleteAllRecordsInTable:(NSString*)table;

#pragma mark -
#pragma mark Save context methods

/*!
 @function Save managedobjectcontext and provide error message handling
 */
+(void) saveContext;

@end

The .m file:

#import "CoreDataAccess.h"

@implementation CoreDataAccess

static NSManagedObjectContext *managedObjectContext;

#pragma mark -
#pragma mark ManagedObjectContext accessors

+(void) setManagedObjectContext:(NSManagedObjectContext*)context
{
    managedObjectContext = context;
}

+(NSManagedObjectContext*) getManagedObjectContext
{
    return managedObjectContext;
}

#pragma mark -
#pragma mark Retrieval Methods - without faulting

+(NSArray*) getRecordsWithoutFaultingForTable:(NSString*)table
{
    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    // needed to prevent faults being returned
    [fetchRequest setReturnsObjectsAsFaults:NO];

    [fetchRequest setEntity:entity];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

+(NSArray*) getRecordsWithoutFaultingForTable:(NSString *)table withPredicate:(NSPredicate *)prd
{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    // needed to prevent faults being returned
    [fetchRequest setReturnsObjectsAsFaults:NO];

    [fetchRequest setEntity:entity];

    [fetchRequest setPredicate:prd];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}


+(NSArray*) getRecordsWithoutFaultingForTable:(NSString*)table WithStringPredicate:(NSString*)prd
{
    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    // needed to prevent faults being returned
    [fetchRequest setReturnsObjectsAsFaults:NO];

    [fetchRequest setEntity:entity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:prd];

    [fetchRequest setPredicate:predicate];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

#pragma mark -
#pragma mark Retrieval Methods - With faulting

+(NSArray*) getRecordsForTable:(NSString*)table
{
    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    [fetchRequest setEntity:entity];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

+(NSArray*) getRecordsForTable:(NSString *)table withPredicate:(NSPredicate *)prd
{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    [fetchRequest setEntity:entity];

    [fetchRequest setPredicate:prd];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

+(NSArray*) getRecordsForTable:(NSString*)table WithStringPredicate:(NSString*)prd
{
    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    [fetchRequest setEntity:entity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:prd];

    [fetchRequest setPredicate:predicate];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    return records;
}

+(NSArray*) getRecordsForTable:(NSString*)table Top:(NSNumber*)top OnColumn:(NSString*)column Ascending:(Boolean)order{

    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    [fetchRequest setEntity:entity];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:column ascending:order];

    NSArray *descriptors = [NSArray arrayWithObject:sortDescriptor];

    NSArray* sortedReadings = [NSArray arrayWithArray:[records sortedArrayUsingDescriptors:descriptors]];

    NSMutableArray* topRecords = [[[NSMutableArray alloc] initWithCapacity:[top intValue]] autorelease];

    for (int i = 0; i < [top intValue]; i++) {
        [topRecords addObject:[sortedReadings objectAtIndex:i]];
    }

    return topRecords;

}

+(NSArray*) getRecordsForTable:(NSString*)table OnColumn:(NSString*)column Ascending:(Boolean)order{
    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    [fetchRequest setEntity:entity];

    NSArray *records = [managedObjectContext executeFetchRequest:fetchRequest error:nil];

    [fetchRequest release];

    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:column ascending:order];

    NSArray *descriptors = [NSArray arrayWithObject:sortDescriptor];

    NSArray* sortedReadings = [NSArray arrayWithArray:[records sortedArrayUsingDescriptors:descriptors]];

    return sortedReadings;

}



#pragma mark -
#pragma mark Delete methods

+(void) deleteRecord:(NSManagedObject *)object{
    [managedObjectContext deleteObject:object];

    [self saveContext];
}

+(void) deleteAllRecordsInTable:(NSString*)table
{
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:table inManagedObjectContext:managedObjectContext];

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];

    // needed to prevent faults being returned
    [fetchRequest setReturnsObjectsAsFaults:NO];

    [fetchRequest setEntity:entity];

    NSArray* resultsArray = [managedObjectContext executeFetchRequest:fetchRequest error:nil];
    [fetchRequest release];
    for (NSManagedObject *managedObject in resultsArray) {
        [managedObjectContext deleteObject:managedObject];
    }

    [self saveContext];
}

#pragma mark -
#pragma mark Save context methods

+(void) saveContext
{
    NSError* error = nil;
    if (![managedObjectContext save:&error]) {
        NSLog(@"Error with database transaction: %@", error);
    }
}

@end

And to set it up, you need to pass it your context in your app delegate. I always include it in the "didFinishLaunchingWithOptions" method

[CoreDataAccess setManagedObjectContext:self.managedObjectContext];

Head on over to my GitHub account for the most up-to-date code base