From 5efcfe2c41420a515dec1ce633047cd59a5729aa Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Mon, 10 Dec 2012 17:12:53 -0500 Subject: [PATCH] Eliminate remaining use of keyed subscript access --- Code/CoreData/RKEntityByAttributeCache.m | 2 +- Code/CoreData/RKEntityMapping.m | 2 +- Code/CoreData/RKRelationshipConnectionOperation.m | 2 +- Code/Network/RKManagedObjectRequestOperation.m | 10 ++++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Code/CoreData/RKEntityByAttributeCache.m b/Code/CoreData/RKEntityByAttributeCache.m index 6bec2fcd..324c6427 100644 --- a/Code/CoreData/RKEntityByAttributeCache.m +++ b/Code/CoreData/RKEntityByAttributeCache.m @@ -48,7 +48,7 @@ static NSString *RKCacheKeyForEntityWithAttributeValues(NSEntityDescription *ent NSArray *sortedAttributes = [[attributeValues allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; NSMutableArray *sortedValues = [NSMutableArray arrayWithCapacity:[sortedAttributes count]]; [sortedAttributes enumerateObjectsUsingBlock:^(NSString *attributeName, NSUInteger idx, BOOL *stop) { - id cacheKeyValue = RKCacheKeyValueForEntityAttributeWithValue(entity, attributeName, attributeValues[attributeName]); + id cacheKeyValue = RKCacheKeyValueForEntityAttributeWithValue(entity, attributeName, [attributeValues objectForKey:attributeName]); [sortedValues addObject:cacheKeyValue]; }]; diff --git a/Code/CoreData/RKEntityMapping.m b/Code/CoreData/RKEntityMapping.m index aaef2e57..5cf76003 100644 --- a/Code/CoreData/RKEntityMapping.m +++ b/Code/CoreData/RKEntityMapping.m @@ -242,7 +242,7 @@ static BOOL entityIdentificationInferenceEnabled = YES; NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:[connectionSpecifier count]]; for (NSString *sourceAttribute in connectionSpecifier) { NSString *destinationAttribute = [self transformSourceKeyPath:sourceAttribute]; - attributes[sourceAttribute] = destinationAttribute; + [attributes setObject:destinationAttribute forKey:sourceAttribute]; } connection = [[RKConnectionDescription alloc] initWithRelationship:relationship attributes:attributes]; } else if ([connectionSpecifier isKindOfClass:[NSDictionary class]]) { diff --git a/Code/CoreData/RKRelationshipConnectionOperation.m b/Code/CoreData/RKRelationshipConnectionOperation.m index bfd19047..8e0b4721 100644 --- a/Code/CoreData/RKRelationshipConnectionOperation.m +++ b/Code/CoreData/RKRelationshipConnectionOperation.m @@ -43,7 +43,7 @@ static NSDictionary *RKConnectionAttributeValuesWithObject(RKConnectionDescripti NSCAssert([connection isForeignKeyConnection], @"Only valid for a foreign key connection"); NSMutableDictionary *destinationEntityAttributeValues = [NSMutableDictionary dictionaryWithCapacity:[connection.attributes count]]; for (NSString *sourceAttribute in connection.attributes) { - NSString *destinationAttribute = connection.attributes[sourceAttribute]; + NSString *destinationAttribute = [connection.attributes objectForKey:sourceAttribute]; id sourceValue = [managedObject valueForKey:sourceAttribute]; [destinationEntityAttributeValues setValue:sourceValue forKey:destinationAttribute]; } diff --git a/Code/Network/RKManagedObjectRequestOperation.m b/Code/Network/RKManagedObjectRequestOperation.m index acb58946..7111a88b 100644 --- a/Code/Network/RKManagedObjectRequestOperation.m +++ b/Code/Network/RKManagedObjectRequestOperation.m @@ -40,13 +40,15 @@ NSArray *RKArrayOfFetchRequestFromBlocksWithURL(NSArray *fetchRequestBlocks, NSU return fetchRequests; } +// RKManagedObjectOrArrayOfManagedObjectsInContext(id managedObjectOrArrayOfManagedObjects, NSManagedObjectContext *managedObjectContext); +// Find the key paths for all entity mappings in the graph whose parent objects are not other managed objects + static NSDictionary *RKDictionaryOfManagedObjectsInContextFromDictionaryOfManagedObjects(NSDictionary *dictionaryOfManagedObjects, NSManagedObjectContext *managedObjectContext) { NSMutableDictionary *newDictionary = [[NSMutableDictionary alloc] initWithCapacity:[dictionaryOfManagedObjects count]]; [managedObjectContext performBlockAndWait:^{ - NSError *error = nil; - for (NSString *key in dictionaryOfManagedObjects) { - id value = dictionaryOfManagedObjects[key]; + __block NSError *error = nil; + [dictionaryOfManagedObjects enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) { if ([value isKindOfClass:[NSArray class]]) { NSMutableArray *newValue = [[NSMutableArray alloc] initWithCapacity:[value count]]; for (__strong id object in value) { @@ -64,7 +66,7 @@ static NSDictionary *RKDictionaryOfManagedObjectsInContextFromDictionaryOfManage } [newDictionary setValue:value forKey:key]; - } + }]; }]; return newDictionary;