Skip to content

Commit 0166576

Browse files
committed
Merge branch 'release/v0.20.0-rc1'
2 parents 22dd9ab + 4407523 commit 0166576

File tree

90 files changed

+3674
-1008
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3674
-1008
lines changed

Code/CoreData/NSManagedObjectContext+RKAdditions.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ - (BOOL)saveToPersistentStore:(NSError **)error
4444
__block BOOL success;
4545
[contextToSave performBlockAndWait:^{
4646
success = [contextToSave save:&localError];
47+
if (! success && localError == nil) RKLogWarning(@"Saving of managed object context failed, but a `nil` value for the `error` argument was returned. This typically indicates an invalid implementation of a key-value validation method exists within your model. This violation of the API contract may result in the save operation being mis-interpretted by callers that rely on the availability of the error.");
4748
}];
4849

4950
if (! success) {

Code/CoreData/RKEntityByAttributeCache.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ - (NSManagedObject *)objectWithAttributeValues:(NSDictionary *)attributeValues i
226226

227227
- (NSSet *)objectsWithAttributeValues:(NSDictionary *)attributeValues inContext:(NSManagedObjectContext *)context
228228
{
229-
// TODO: Assert that the attribute values contains all of the cache attributes!!!
230229
NSMutableSet *objects = [NSMutableSet set];
231230
NSArray *cacheKeys = RKCacheKeysForEntityFromAttributeValues(self.entity, attributeValues);
232231
for (NSString *cacheKey in cacheKeys) {
@@ -281,10 +280,12 @@ - (void)removeObjectID:(NSManagedObjectID *)objectID forAttributeValues:(NSDicti
281280
{
282281
@synchronized(self.cacheKeysToObjectIDs) {
283282
if (attributeValues && [attributeValues count]) {
284-
NSString *cacheKey = RKCacheKeyForEntityWithAttributeValues(self.entity, attributeValues);
285-
NSMutableArray *objectIDs = [self.cacheKeysToObjectIDs objectForKey:cacheKey];
286-
if (objectIDs && [objectIDs containsObject:objectID]) {
287-
[objectIDs removeObject:objectID];
283+
NSArray *cacheKeys = RKCacheKeysForEntityFromAttributeValues(self.entity, attributeValues);
284+
for (NSString *cacheKey in cacheKeys) {
285+
NSMutableArray *objectIDs = [self.cacheKeysToObjectIDs objectForKey:cacheKey];
286+
if (objectIDs && [objectIDs containsObject:objectID]) {
287+
[objectIDs removeObject:objectID];
288+
}
288289
}
289290
} else {
290291
RKLogWarning(@"Unable to remove object for object ID %@: empty values dictionary for attributes '%@'", objectID, self.attributes);

Code/CoreData/RKEntityCache.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ - (RKEntityByAttributeCache *)attributeCacheForEntity:(NSEntityDescription *)ent
9696
{
9797
NSParameterAssert(entity);
9898
NSParameterAssert(attributeNames);
99-
for (RKEntityByAttributeCache *cache in self.attributeCaches) {
99+
for (RKEntityByAttributeCache *cache in [self.attributeCaches copy]) {
100100
if ([cache.entity isEqual:entity] && [cache.attributes isEqualToArray:attributeNames]) {
101101
return cache;
102102
}
@@ -109,7 +109,7 @@ - (NSSet *)attributeCachesForEntity:(NSEntityDescription *)entity
109109
{
110110
NSAssert(entity, @"Cannot retrieve attribute caches for a nil entity");
111111
NSMutableSet *set = [NSMutableSet set];
112-
for (RKEntityByAttributeCache *cache in self.attributeCaches) {
112+
for (RKEntityByAttributeCache *cache in [self.attributeCaches copy]) {
113113
if ([cache.entity isEqual:entity]) {
114114
[set addObject:cache];
115115
}

Code/CoreData/RKEntityMapping.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ + (instancetype)mappingForClass:(Class)objectClass
149149

150150
+ (instancetype)mappingForEntityForName:(NSString *)entityName inManagedObjectStore:(RKManagedObjectStore *)managedObjectStore
151151
{
152+
NSParameterAssert(entityName);
153+
NSParameterAssert(managedObjectStore);
152154
NSEntityDescription *entity = [[managedObjectStore.managedObjectModel entitiesByName] objectForKey:entityName];
155+
NSAssert(entity, @"Unable to find an Entity with the name '%@' in the managed object model", entityName);
153156
return [[self alloc] initWithEntity:entity];
154157
}
155158

@@ -180,8 +183,10 @@ - (id)initWithClass:(Class)objectClass
180183
- (id)copyWithZone:(NSZone *)zone
181184
{
182185
RKEntityMapping *copy = [super copyWithZone:zone];
186+
copy.entity = self.entity;
183187
copy.identificationAttributes = self.identificationAttributes;
184188
copy.identificationPredicate = self.identificationPredicate;
189+
copy.deletionPredicate = self.deletionPredicate;
185190

186191
for (RKConnectionDescription *connection in self.connections) {
187192
[copy addConnection:[connection copy]];
@@ -235,7 +240,7 @@ - (NSArray *)connections
235240
- (void)addConnectionForRelationship:(id)relationshipOrName connectedBy:(id)connectionSpecifier
236241
{
237242
NSRelationshipDescription *relationship = [relationshipOrName isKindOfClass:[NSRelationshipDescription class]] ? relationshipOrName : [[self.entity relationshipsByName] valueForKey:relationshipOrName];
238-
NSAssert(relationship, @"No relatiobship was found named '%@' in the '%@' entity", relationshipOrName, [self.entity name]);
243+
NSAssert(relationship, @"No relationship was found named '%@' in the '%@' entity", relationshipOrName, [self.entity name]);
239244
RKConnectionDescription *connection = nil;
240245
if ([connectionSpecifier isKindOfClass:[NSString class]]) {
241246
NSString *sourceAttribute = connectionSpecifier;

Code/CoreData/RKFetchRequestManagedObjectCache.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
#define RKLogComponent RKlcl_cRestKitCoreData
1818

1919
/*
20-
NOTE: At the moment this cache key assume that the structure of the values for each key in the `attributeValues` in constant
21-
i.e. if you have `userID`, it will always be a single value, or `userIDs` will always be an array.
22-
It will need to be reimplemented if changes in attribute values occur during the life of a single cache
20+
This function computes a cache key given a dictionary of attribute values. Each attribute name is used as a fragment within the aggregate cache key. A suffix qualifier is appended that differentiates singular vs. collection attribute values so that '==' and 'IN' predicates are computed appropriately.
2321
*/
24-
static NSString *RKPredicateCacheKeyForAttributes(NSArray *attributeNames)
22+
static NSString *RKPredicateCacheKeyForAttributeValues(NSDictionary *attributesValues)
2523
{
26-
return [[attributeNames sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] componentsJoinedByString:@":"];
24+
NSArray *sortedKeys = [[attributesValues allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
25+
NSMutableArray *keyFragments = [NSMutableArray array];
26+
for (NSString *attributeName in sortedKeys) {
27+
id value = [attributesValues objectForKey:attributeName];
28+
char suffix = ([value respondsToSelector:@selector(count)]) ? '+' : '.';
29+
NSString *attributeKey = [NSString stringWithFormat:@"%@%c", attributeName, suffix];
30+
[keyFragments addObject:attributeKey];
31+
}
32+
return [keyFragments componentsJoinedByString:@":"];
2733
}
2834

2935
// NOTE: We build a dynamic format string here because `NSCompoundPredicate` does not support use of substiution variables
@@ -65,7 +71,7 @@ - (NSSet *)managedObjectsWithEntity:(NSEntityDescription *)entity
6571
NSAssert(attributeValues, @"Cannot retrieve cached objects without attribute values to identify them with.");
6672
NSAssert(managedObjectContext, @"Cannot find existing managed object with a nil context");
6773

68-
NSString *predicateCacheKey = RKPredicateCacheKeyForAttributes([attributeValues allKeys]);
74+
NSString *predicateCacheKey = RKPredicateCacheKeyForAttributeValues(attributeValues);
6975
NSPredicate *substitutionPredicate = [self.predicateCache objectForKey:predicateCacheKey];
7076
if (! substitutionPredicate) {
7177
substitutionPredicate = RKPredicateWithSubsitutionVariablesForAttributeValues(attributeValues);

0 commit comments

Comments
 (0)