Skip to content

Commit

Permalink
Merge branch 'hotfix/0.10.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Aug 8, 2012
2 parents f11a538 + 149edd9 commit 8d5e315
Show file tree
Hide file tree
Showing 250 changed files with 8,025 additions and 6,121 deletions.
1 change: 1 addition & 0 deletions Code/CoreData/CoreData.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "NSManagedObject+ActiveRecord.h"
#import "RKManagedObjectStore.h"
#import "RKManagedObjectSeeder.h"
#import "RKManagedObjectLoader.h"
#import "RKManagedObjectMapping.h"
#import "RKManagedObjectMappingOperation.h"
#import "RKManagedObjectCaching.h"
Expand Down
10 changes: 5 additions & 5 deletions Code/CoreData/NSEntityDescription+RKAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ extern NSString * const RKEntityDescriptionPrimaryKeyAttributeValuePredicateSubs
value. This predicate is constructed by evaluating the cached predicate returned by the
predicateForPrimaryKeyAttribute with a dictionary of substitution variables specifying that
$PRIMARY_KEY_VALUE is equal to the given value.
**NOTE**: This method considers the type of the receiver's primary key attribute when constructing
the predicate. It will coerce the given value into either an NSString or an NSNumber as
the predicate. It will coerce the given value into either an NSString or an NSNumber as
appropriate. This behavior is a convenience to avoid annoying issues related to Core Data's
handling of predicates for NSString and NSNumber types that were not appropriately casted.
@return A predicate speciying that the value of the primary key attribute is equal to a given value.
*/
- (NSPredicate *)predicateForPrimaryKeyAttributeWithValue:(id)value;

/**
Coerces the given value into the class representing the primary key. Currently support NSString
and NSNumber coercsions.
@bug **NOTE** This API is temporary and will be deprecated and replaced.
@since 0.10.1
@since 0.10.1
*/
- (id)coerceValueForPrimaryKey:(id)primaryKeyValue;

Expand Down
8 changes: 4 additions & 4 deletions Code/CoreData/NSEntityDescription+RKAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ - (Class)primaryKeyAttributeClass
if (attributeDescription) {
return NSClassFromString(attributeDescription.attributeValueClassName);
}

return nil;
}

- (NSString *)primaryKeyAttributeName
{
// Check for an associative object reference
NSString *primaryKeyAttribute = (NSString *) objc_getAssociatedObject(self, &primaryKeyAttributeNameKey);
NSString *primaryKeyAttribute = (NSString *)objc_getAssociatedObject(self, &primaryKeyAttributeNameKey);

// Fall back to the userInfo dictionary
if (! primaryKeyAttribute) {
Expand All @@ -71,7 +71,7 @@ - (void)setPrimaryKeyAttributeName:(NSString *)primaryKeyAttributeName

- (NSPredicate *)predicateForPrimaryKeyAttribute
{
return (NSPredicate *) objc_getAssociatedObject(self, &primaryKeyPredicateKey);
return (NSPredicate *)objc_getAssociatedObject(self, &primaryKeyPredicateKey);
}

- (id)coerceValueForPrimaryKey:(id)primaryKeyValue
Expand All @@ -92,7 +92,7 @@ - (id)coerceValueForPrimaryKey:(id)primaryKeyValue
}
}
}

return searchValue;
}

Expand Down
30 changes: 15 additions & 15 deletions Code/CoreData/NSManagedObject+ActiveRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,59 +31,59 @@
* The NSEntityDescription for the Subclass
* defaults to the subclass className, may be overridden
*/
+ (NSEntityDescription*)entity;
+ (NSEntityDescription *)entity;

/**
* Returns an initialized NSFetchRequest for the entity, with no predicate
*/
+ (NSFetchRequest*)fetchRequest;
+ (NSFetchRequest *)fetchRequest;

/**
* Fetches all objects from the persistent store identified by the fetchRequest
*/
+ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest;
+ (NSArray *)objectsWithFetchRequest:(NSFetchRequest *)fetchRequest;

/**
* Retrieves the number of objects that would be retrieved by the fetchRequest,
* if executed
*/
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest*)fetchRequest;
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest *)fetchRequest;

/**
* Fetches all objects from the persistent store via a set of fetch requests and
* returns all results in a single array.
*/
+ (NSArray*)objectsWithFetchRequests:(NSArray*)fetchRequests;
+ (NSArray *)objectsWithFetchRequests:(NSArray *)fetchRequests;

/**
* Fetches the first object identified by the fetch request. A limit of one will be
* applied to the fetch request before dispatching.
*/
+ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest;
+ (id)objectWithFetchRequest:(NSFetchRequest *)fetchRequest;

/**
* Fetches all objects from the persistent store by constructing a fetch request and
* applying the predicate supplied. A short-cut for doing filtered searches on the objects
* of this class under management.
*/
+ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate;
+ (NSArray *)objectsWithPredicate:(NSPredicate *)predicate;

/**
* Fetches the first object matching a predicate from the persistent store. A fetch request
* will be constructed for you and a fetch limit of 1 will be applied.
*/
+ (id)objectWithPredicate:(NSPredicate*)predicate;
+ (id)objectWithPredicate:(NSPredicate *)predicate;

/**
* Fetches all managed objects of this class from the persistent store as an array
*/
+ (NSArray*)allObjects;
+ (NSArray *)allObjects;

/**
* Returns a count of all managed objects of this class in the persistent store. On
* error, will populate the error argument
*/
+ (NSUInteger)count:(NSError**)error;
+ (NSUInteger)count:(NSError **)error;

/**
* Returns a count of all managed objects of this class in the persistent store. Deprecated
Expand Down Expand Up @@ -124,7 +124,7 @@

////////////////////////////////////////////////////////////////////////////////////////////////////

+ (NSManagedObjectContext*)currentContext;
+ (NSManagedObjectContext *)currentContext;

+ (void)handleErrors:(NSError *)error;

Expand Down Expand Up @@ -152,8 +152,8 @@
+ (NSNumber *)numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm;
+ (NSNumber *)numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;

+ (BOOL) hasAtLeastOneEntity;
+ (BOOL) hasAtLeastOneEntityInContext:(NSManagedObjectContext *)context;
+ (BOOL)hasAtLeastOneEntity;
+ (BOOL)hasAtLeastOneEntityInContext:(NSManagedObjectContext *)context;

+ (NSFetchRequest *)requestAll;
+ (NSFetchRequest *)requestAllInContext:(NSManagedObjectContext *)context;
Expand All @@ -180,8 +180,8 @@
+ (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context;

+ (NSNumber *)maxValueFor:(NSString *)property;
+ (id) objectWithMinValueFor:(NSString *)property;
+ (id) objectWithMinValueFor:(NSString *)property inContext:(NSManagedObjectContext *)context;
+ (id)objectWithMinValueFor:(NSString *)property;
+ (id)objectWithMinValueFor:(NSString *)property inContext:(NSManagedObjectContext *)context;

+ (id)findFirst;
+ (id)findFirstInContext:(NSManagedObjectContext *)context;
Expand Down
89 changes: 54 additions & 35 deletions Code/CoreData/NSManagedObject+ActiveRecord.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@

@implementation NSManagedObjectContext (ActiveRecord)

+ (NSManagedObjectContext *)defaultContext {
+ (NSManagedObjectContext *)defaultContext
{
return defaultContext;
}

+ (void)setDefaultContext:(NSManagedObjectContext *)newDefaultContext {
+ (void)setDefaultContext:(NSManagedObjectContext *)newDefaultContext
{
[newDefaultContext retain];
[defaultContext release];
defaultContext = newDefaultContext;
}

+ (NSManagedObjectContext *)contextForCurrentThread {
+ (NSManagedObjectContext *)contextForCurrentThread
{
NSAssert([RKManagedObjectStore defaultObjectStore], @"[RKManagedObjectStore defaultObjectStore] cannot be nil");
return [[RKManagedObjectStore defaultObjectStore] managedObjectContextForCurrentThread];
}
Expand All @@ -51,109 +54,125 @@ @implementation NSManagedObject (ActiveRecord)

#pragma mark - RKManagedObject methods

+ (NSEntityDescription*)entity {
NSString* className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
+ (NSEntityDescription *)entity
{
NSString *className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
return [NSEntityDescription entityForName:className inManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
}

+ (NSFetchRequest*)fetchRequest {
+ (NSFetchRequest *)fetchRequest
{
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [self entity];
[fetchRequest setEntity:entity];
return fetchRequest;
}

+ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest {
NSError* error = nil;
NSArray* objects = [[NSManagedObjectContext contextForCurrentThread] executeFetchRequest:fetchRequest error:&error];
+ (NSArray *)objectsWithFetchRequest:(NSFetchRequest *)fetchRequest
{
NSError *error = nil;
NSArray *objects = [[NSManagedObjectContext contextForCurrentThread] executeFetchRequest:fetchRequest error:&error];
if (objects == nil) {
RKLogError(@"Error: %@", [error localizedDescription]);
}
return objects;
}

+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest*)fetchRequest {
NSError* error = nil;
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest *)fetchRequest
{
NSError *error = nil;
NSUInteger objectCount = [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:&error];
if (objectCount == NSNotFound) {
RKLogError(@"Error: %@", [error localizedDescription]);
}
return objectCount;
}

+ (NSArray*)objectsWithFetchRequests:(NSArray*)fetchRequests {
NSMutableArray* mutableObjectArray = [[NSMutableArray alloc] init];
for (NSFetchRequest* fetchRequest in fetchRequests) {
+ (NSArray *)objectsWithFetchRequests:(NSArray *)fetchRequests
{
NSMutableArray *mutableObjectArray = [[NSMutableArray alloc] init];
for (NSFetchRequest *fetchRequest in fetchRequests) {
[mutableObjectArray addObjectsFromArray:[self objectsWithFetchRequest:fetchRequest]];
}
NSArray* objects = [NSArray arrayWithArray:mutableObjectArray];
NSArray *objects = [NSArray arrayWithArray:mutableObjectArray];
[mutableObjectArray release];
return objects;
}

+ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest {
+ (id)objectWithFetchRequest:(NSFetchRequest *)fetchRequest
{
[fetchRequest setFetchLimit:1];
NSArray* objects = [self objectsWithFetchRequest:fetchRequest];
NSArray *objects = [self objectsWithFetchRequest:fetchRequest];
if ([objects count] == 0) {
return nil;
} else {
return [objects objectAtIndex:0];
}
}

+ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate {
NSFetchRequest* fetchRequest = [self fetchRequest];
+ (NSArray *)objectsWithPredicate:(NSPredicate *)predicate
{
NSFetchRequest *fetchRequest = [self fetchRequest];
[fetchRequest setPredicate:predicate];
return [self objectsWithFetchRequest:fetchRequest];
}

+ (id)objectWithPredicate:(NSPredicate*)predicate {
NSFetchRequest* fetchRequest = [self fetchRequest];
+ (id)objectWithPredicate:(NSPredicate *)predicate
{
NSFetchRequest *fetchRequest = [self fetchRequest];
[fetchRequest setPredicate:predicate];
return [self objectWithFetchRequest:fetchRequest];
}

+ (NSArray*)allObjects {
+ (NSArray *)allObjects
{
return [self objectsWithPredicate:nil];
}

+ (NSUInteger)count:(NSError**)error {
NSFetchRequest* fetchRequest = [self fetchRequest];
+ (NSUInteger)count:(NSError **)error
{
NSFetchRequest *fetchRequest = [self fetchRequest];
return [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:error];
}

+ (NSUInteger)count {
+ (NSUInteger)count
{
NSError *error = nil;
return [self count:&error];
}

+ (id)object {
+ (id)object
{
id object = [[self alloc] initWithEntity:[self entity] insertIntoManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
return [object autorelease];
}

- (BOOL)isNew {
- (BOOL)isNew
{
NSDictionary *vals = [self committedValuesForKeys:nil];
return [vals count] == 0;
}

+ (id)findByPrimaryKey:(id)primaryKeyValue inContext:(NSManagedObjectContext *)context {
+ (id)findByPrimaryKey:(id)primaryKeyValue inContext:(NSManagedObjectContext *)context
{
NSPredicate *predicate = [[self entityDescriptionInContext:context] predicateForPrimaryKeyAttributeWithValue:primaryKeyValue];
if (! predicate) {
RKLogWarning(@"Attempt to findByPrimaryKey for entity with nil primaryKeyAttribute. Set the primaryKeyAttributeName and try again! %@", self);
return nil;
}

return [self findFirstWithPredicate:predicate inContext:context];
}

+ (id)findByPrimaryKey:(id)primaryKeyValue {
+ (id)findByPrimaryKey:(id)primaryKeyValue
{
return [self findByPrimaryKey:primaryKeyValue inContext:[NSManagedObjectContext contextForCurrentThread]];
}

#pragma mark - MagicalRecord Ported Methods

+ (NSManagedObjectContext*)currentContext; {
+ (NSManagedObjectContext *)currentContext;
{
return [NSManagedObjectContext contextForCurrentThread];
}

Expand Down Expand Up @@ -276,7 +295,7 @@ + (NSArray *)propertiesNamed:(NSArray *)properties
}
else
{
RKLogError(@"Property '%@' not found in %@ properties for %@", propertyName, [propDict count], NSStringFromClass(self));
RKLogError(@"Property '%@' not found in %d properties for %@", propertyName, [propDict count], NSStringFromClass(self));
}
}
}
Expand All @@ -292,7 +311,7 @@ + (NSArray *)sortAscending:(BOOL)ascending attributes:(id)attributesToSortBy, ..
id attributeName;
va_list variadicArguments;
va_start(variadicArguments, attributesToSortBy);
while ((attributeName = va_arg(variadicArguments, id))!= nil)
while ((attributeName = va_arg(variadicArguments, id)) != nil)
{
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:attributeName ascending:ascending];
[attributes addObject:sortDescriptor];
Expand All @@ -305,7 +324,7 @@ + (NSArray *)sortAscending:(BOOL)ascending attributes:(id)attributesToSortBy, ..
{
va_list variadicArguments;
va_start(variadicArguments, attributesToSortBy);
[attributes addObject:[[[NSSortDescriptor alloc] initWithKey:attributesToSortBy ascending:ascending] autorelease] ];
[attributes addObject:[[[NSSortDescriptor alloc] initWithKey:attributesToSortBy ascending:ascending] autorelease]];
va_end(variadicArguments);
}

Expand Down Expand Up @@ -457,7 +476,7 @@ + (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)asce
[request setIncludesSubentities:NO];
[request setFetchBatchSize:[self defaultBatchSize]];

if (sortTerm != nil){
if (sortTerm != nil) {
NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey:sortTerm ascending:ascending];
[request setSortDescriptors:[NSArray arrayWithObject:sortBy]];
[sortBy release];
Expand Down
2 changes: 1 addition & 1 deletion Code/CoreData/NSManagedObjectContext+RKAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @implementation NSManagedObjectContext (RKAdditions)

- (RKManagedObjectStore *)managedObjectStore
{
return (RKManagedObjectStore *) objc_getAssociatedObject(self, &NSManagedObject_RKManagedObjectStoreAssociatedKey);
return (RKManagedObjectStore *)objc_getAssociatedObject(self, &NSManagedObject_RKManagedObjectStoreAssociatedKey);
}

- (void)setManagedObjectStore:(RKManagedObjectStore *)managedObjectStore
Expand Down
Loading

0 comments on commit 8d5e315

Please sign in to comment.