Permalink
Browse files

Merge branch 'feature/743-whitespace-cleanup' into development

  • Loading branch information...
2 parents ee30436 + 016f13d commit 185874dac7160d8ad55ba7502d366d9ec9d8b487 @blakewatters blakewatters committed May 17, 2012
Showing with 3,858 additions and 3,858 deletions.
  1. +3 −3 Code/CoreData/CoreData.h
  2. +6 −6 Code/CoreData/NSEntityDescription+RKAdditions.h
  3. +2 −2 Code/CoreData/NSEntityDescription+RKAdditions.m
  4. +4 −4 Code/CoreData/NSManagedObject+ActiveRecord.h
  5. +305 −305 Code/CoreData/NSManagedObject+ActiveRecord.m
  6. +19 −19 Code/CoreData/RKEntityByAttributeCache.h
  7. +21 −21 Code/CoreData/RKEntityByAttributeCache.m
  8. +15 −15 Code/CoreData/RKEntityCache.h
  9. +5 −5 Code/CoreData/RKEntityCache.m
  10. +3 −3 Code/CoreData/RKFetchRequestManagedObjectCache.m
  11. +3 −3 Code/CoreData/RKInMemoryManagedObjectCache.m
  12. +3 −3 Code/CoreData/RKManagedObjectCaching.h
  13. +5 −5 Code/CoreData/RKManagedObjectLoader.h
  14. +22 −22 Code/CoreData/RKManagedObjectLoader.m
  15. +10 −10 Code/CoreData/RKManagedObjectMapping.h
  16. +19 −19 Code/CoreData/RKManagedObjectMapping.m
  17. +4 −4 Code/CoreData/RKManagedObjectMappingOperation.h
  18. +8 −8 Code/CoreData/RKManagedObjectMappingOperation.m
  19. +1 −1 Code/CoreData/RKManagedObjectSearchEngine.h
  20. +43 −43 Code/CoreData/RKManagedObjectSearchEngine.m
  21. +4 −4 Code/CoreData/RKManagedObjectSeeder.h
  22. +52 −52 Code/CoreData/RKManagedObjectSeeder.m
  23. +10 −10 Code/CoreData/RKManagedObjectStore.h
  24. +144 −144 Code/CoreData/RKManagedObjectStore.m
  25. +3 −3 Code/CoreData/RKManagedObjectThreadSafeInvocation.h
  26. +10 −10 Code/CoreData/RKManagedObjectThreadSafeInvocation.m
  27. +1 −1 Code/CoreData/RKObjectMappingProvider+CoreData.h
  28. +3 −3 Code/CoreData/RKObjectPropertyInspector+CoreData.h
  29. +9 −9 Code/CoreData/RKObjectPropertyInspector+CoreData.m
  30. +11 −11 Code/CoreData/RKSearchableManagedObject.h
  31. +11 −11 Code/CoreData/RKSearchableManagedObject.m
  32. +4 −4 Code/Network/NSData+RKAdditions.h
  33. +13 −13 Code/Network/NSData+RKAdditions.m
  34. +6 −6 Code/Network/NSDictionary+RKRequestSerialization.h
  35. +5 −5 Code/Network/NSDictionary+RKRequestSerialization.m
  36. +7 −7 Code/Network/NSObject+URLEncoding.m
  37. +3 −3 Code/Network/Network.h
  38. +11 −11 Code/Network/RKClient.h
  39. +46 −46 Code/Network/RKClient.m
  40. +4 −4 Code/Network/RKNotifications.h
  41. +3 −3 Code/Network/RKNotifications.m
  42. +27 −27 Code/Network/RKOAuthClient.h
  43. +24 −24 Code/Network/RKOAuthClient.m
  44. +25 −25 Code/Network/RKParams.h
  45. +28 −28 Code/Network/RKParams.m
  46. +16 −16 Code/Network/RKParamsAttachment.h
  47. +87 −87 Code/Network/RKParamsAttachment.m
  48. +43 −43 Code/Network/RKReachabilityObserver.h
  49. +123 −123 Code/Network/RKReachabilityObserver.m
  50. +1 −1 Code/Network/RKRequest.h
  51. +152 −152 Code/Network/RKRequest.m
  52. +16 −16 Code/Network/RKRequestCache.h
  53. +65 −65 Code/Network/RKRequestCache.m
  54. +33 −33 Code/Network/RKRequestQueue.h
  55. +85 −85 Code/Network/RKRequestQueue.m
  56. +10 −10 Code/Network/RKRequestSerializable.h
  57. +6 −6 Code/Network/RKRequestSerialization.h
  58. +6 −6 Code/Network/RKRequestSerialization.m
  59. +3 −3 Code/Network/RKRequest_Internals.h
  60. +44 −44 Code/Network/RKResponse.h
  61. +138 −138 Code/Network/RKResponse.m
  62. +32 −32 Code/Network/RKURL.h
  63. +15 −15 Code/Network/RKURL.m
  64. +3 −3 Code/ObjectMapping/ObjectMapping.h
  65. +3 −3 Code/ObjectMapping/RKConfigurationDelegate.h
  66. +7 −7 Code/ObjectMapping/RKDynamicObjectMapping.h
  67. +10 −10 Code/ObjectMapping/RKDynamicObjectMapping.m
  68. +3 −3 Code/ObjectMapping/RKErrorMessage.h
  69. +3 −3 Code/ObjectMapping/RKErrorMessage.m
  70. +6 −6 Code/ObjectMapping/RKMappingOperationQueue.h
  71. +1 −1 Code/ObjectMapping/RKMappingOperationQueue.m
  72. +5 −5 Code/ObjectMapping/RKObjectAttributeMapping.h
  73. +5 −5 Code/ObjectMapping/RKObjectAttributeMapping.m
  74. +27 −27 Code/ObjectMapping/RKObjectLoader.h
  75. +60 −60 Code/ObjectMapping/RKObjectLoader.m
  76. +3 −3 Code/ObjectMapping/RKObjectLoader_Internals.h
  77. +51 −51 Code/ObjectMapping/RKObjectManager.h
  78. +64 −64 Code/ObjectMapping/RKObjectManager.m
  79. +4 −4 Code/ObjectMapping/RKObjectMapper.h
  80. +29 −29 Code/ObjectMapping/RKObjectMapper.m
  81. +3 −3 Code/ObjectMapping/RKObjectMapperError.h
  82. +3 −3 Code/ObjectMapping/RKObjectMapper_Private.h
  83. +37 −37 Code/ObjectMapping/RKObjectMapping.h
  84. +13 −13 Code/ObjectMapping/RKObjectMapping.m
  85. +11 −11 Code/ObjectMapping/RKObjectMappingDefinition.h
  86. +6 −6 Code/ObjectMapping/RKObjectMappingOperation.h
  87. +54 −54 Code/ObjectMapping/RKObjectMappingOperation.m
  88. +3 −3 Code/ObjectMapping/RKObjectMappingProvider+Contexts.h
  89. +48 −48 Code/ObjectMapping/RKObjectMappingProvider.h
  90. +9 −9 Code/ObjectMapping/RKObjectMappingProvider.m
  91. +3 −3 Code/ObjectMapping/RKObjectMappingResult.h
  92. +8 −8 Code/ObjectMapping/RKObjectMappingResult.m
  93. +35 −35 Code/ObjectMapping/RKObjectPaginator.h
  94. +16 −16 Code/ObjectMapping/RKObjectPaginator.m
  95. +4 −4 Code/ObjectMapping/RKObjectPropertyInspector.h
  96. +61 −61 Code/ObjectMapping/RKObjectPropertyInspector.m
  97. +3 −3 Code/ObjectMapping/RKObjectRelationshipMapping.h
  98. +4 −4 Code/ObjectMapping/RKObjectRelationshipMapping.m
  99. +10 −10 Code/ObjectMapping/RKObjectRouter.h
  100. +6 −6 Code/ObjectMapping/RKObjectRouter.m
  101. +3 −3 Code/ObjectMapping/RKObjectSerializer.h
  102. +12 −12 Code/ObjectMapping/RKObjectSerializer.m
  103. +15 −15 Code/ObjectMapping/RKParserRegistry.h
  104. +24 −24 Code/ObjectMapping/RKParserRegistry.m
  105. +3 −3 Code/ObjectMapping/RKRouter.h
  106. +4 −4 Code/RestKit.h
  107. +1 −1 Code/Support/NSArray+RKAdditions.h
  108. +34 −34 Code/Support/NSArray+RKAdditions.m
  109. +2 −2 Code/Support/NSBundle+RKAdditions.m
  110. +7 −7 Code/Support/NSDictionary+RKAdditions.h
  111. +14 −14 Code/Support/NSDictionary+RKAdditions.m
  112. +23 −23 Code/Support/NSString+RKAdditions.h
  113. +9 −9 Code/Support/NSString+RKAdditions.m
  114. +6 −6 Code/Support/NSURL+RKAdditions.h
  115. +3 −3 Code/Support/NSURL+RKAdditions.m
  116. +3 −3 Code/Support/Parsers/JSON/RKJSONParserJSONKit.h
  117. +5 −5 Code/Support/Parsers/JSON/RKJSONParserJSONKit.m
  118. +4 −4 Code/Support/Parsers/XML/RKXMLParserXMLReader.h
  119. +3 −3 Code/Support/RKAlert.h
  120. +5 −5 Code/Support/RKAlert.m
  121. +5 −5 Code/Support/RKBenchmark.h
  122. +4 −4 Code/Support/RKBenchmark.m
  123. +2 −2 Code/Support/RKCache.h
  124. +95 −95 Code/Support/RKCache.m
  125. +2 −2 Code/Support/RKDirectory.h
  126. +10 −10 Code/Support/RKDirectory.m
  127. +10 −10 Code/Support/RKDotNetDateFormatter.h
  128. +4 −4 Code/Support/RKDotNetDateFormatter.m
  129. +4 −4 Code/Support/RKFixCategoryBug.h
  130. +22 −22 Code/Support/RKLog.h
  131. +3 −3 Code/Support/RKLog.m
  132. +3 −3 Code/Support/RKMIMETypes.h
  133. +3 −3 Code/Support/RKMIMETypes.m
  134. +2 −2 Code/Support/RKMutableBlockDictionary.m
  135. +2 −2 Code/Support/RKOrderedDictionary.h
  136. +63 −63 Code/Support/RKOrderedDictionary.m
  137. +3 −3 Code/Support/RKParser.h
  138. +35 −35 Code/Support/RKPathMatcher.h
  139. +5 −5 Code/Support/RKPathMatcher.m
  140. +5 −5 Code/Support/RKPortCheck.h
  141. +14 −14 Code/Support/RKPortCheck.m
  142. +5 −5 Code/Support/RKSearchEngine.h
  143. +54 −54 Code/Support/RKSearchEngine.m
  144. +3 −3 Code/Support/Support.h
  145. +4 −4 Code/Support/lcl_config_components.h
  146. +3 −3 Code/Support/lcl_config_extensions.h
  147. +3 −3 Code/Support/lcl_config_logger.h
  148. +16 −16 Code/Testing/RKMappingTest.h
  149. +11 −11 Code/Testing/RKMappingTest.m
  150. +4 −4 Code/Testing/RKMappingTestExpectation.h
  151. +4 −4 Code/Testing/RKMappingTestExpectation.m
  152. +14 −14 Code/Testing/RKTestFactory.h
  153. +13 −13 Code/Testing/RKTestFactory.m
  154. +1 −1 Code/Testing/RKTestFixture.h
  155. +14 −14 Code/Testing/RKTestNotificationObserver.m
  156. +25 −25 Code/Testing/RKTestResponseLoader.m
  157. +4 −4 Code/UI/RKAbstractTableController.h
  158. +4 −4 Code/UI/RKAbstractTableController.m
  159. +1 −1 Code/UI/RKFetchedResultsTableController.h
  160. +43 −43 Code/UI/RKFetchedResultsTableController.m
  161. +4 −4 Code/UI/RKObjectManager+RKTableController.h
  162. +6 −6 Code/UI/RKTableController.h
  163. +5 −5 Code/UI/RKTableController.m
  164. +1 −1 Code/UI/RKTableItem.m
  165. +3 −3 Code/UI/RKTableViewCellMapping.h
  166. +1 −1 Code/UI/RKTableViewCellMapping.m
  167. +3 −3 Examples/RKCatalog/App/RKCatalogAppDelegate.m
  168. +7 −7 Examples/RKCatalog/App/RootViewController.m
  169. +2 −2 Examples/RKCatalog/Examples/RKAuthenticationExample/RKAuthenticationExample.m
  170. +3 −3 Examples/RKCatalog/Examples/RKBackgroundRequestExample/RKBackgroundRequestExample.m
  171. +14 −14 Examples/RKCatalog/Examples/RKCoreDataExample/RKCoreDataExample.m
  172. +4 −4 Examples/RKCatalog/Examples/RKKeyValueMappingExample/RKKeyValueMappingExample.m
  173. +8 −8 Examples/RKCatalog/Examples/RKParamsExample/RKParamsExample.m
  174. +6 −6 Examples/RKCatalog/Examples/RKReachabilityExample/RKReachabilityExample.m
  175. +14 −14 Examples/RKCatalog/Examples/RKRelationshipMappingExample/RKRelationshipMappingExample.m
  176. +1 −1 Examples/RKCatalog/Examples/RKRequestQueueExample/RKRequestQueueExample.h
  177. +9 −9 Examples/RKCatalog/Examples/RKRequestQueueExample/RKRequestQueueExample.m
  178. +7 −7 Examples/RKTwitter/Classes/RKTStatus.h
  179. +5 −5 Examples/RKTwitter/Classes/RKTStatus.m
  180. +3 −3 Examples/RKTwitter/Classes/RKTUser.h
  181. +3 −3 Examples/RKTwitter/Classes/RKTUser.m
  182. +14 −14 Examples/RKTwitter/Classes/RKTwitterAppDelegate.m
  183. +2 −2 Examples/RKTwitter/Classes/RKTwitterViewController.h
  184. +41 −41 Examples/RKTwitter/Classes/RKTwitterViewController.m
  185. +1 −1 Examples/RKTwitter/main.m
  186. +20 −20 Examples/RKTwitterCoreData/Classes/RKTwitterAppDelegate.m
  187. +2 −2 Examples/RKTwitterCoreData/Classes/RKTwitterViewController.h
  188. +58 −58 Examples/RKTwitterCoreData/Classes/RKTwitterViewController.m
  189. +1 −1 Examples/RKTwitterCoreData/main.m
  190. +1 −1 Examples/RKTwitterCoreData/restkit.json
  191. +1 −1 Examples/RKTwitterCoreData/users.json
  192. +9 −9 Examples/RestKit CLI/RestKit CLI/main.m
  193. +1 −1 Tests/Application/UI/RKFetchedResultsTableControllerTest.m
  194. +15 −15 Tests/Application/UI/RKTableControllerTest.m
  195. +1 −1 Tests/Fixtures/JSON/ArrayOfNestedDictionaries.json
  196. +1 −1 Tests/Fixtures/JSON/ArrayOfResults.json
  197. +1 −1 Tests/Fixtures/JSON/ConnectingParents.json
  198. +1 −1 Tests/Fixtures/JSON/Dynamic/boy.json
  199. +1 −1 Tests/Fixtures/JSON/Dynamic/child.json
  200. +1 −1 Tests/Fixtures/JSON/Dynamic/friends.json
  201. +1 −1 Tests/Fixtures/JSON/Dynamic/girl.json
  202. +1 −1 Tests/Fixtures/JSON/Dynamic/mixed.json
  203. +1 −1 Tests/Fixtures/JSON/Dynamic/parent.json
  204. +1 −1 Tests/Fixtures/JSON/DynamicKeys.json
  205. +1 −1 Tests/Fixtures/JSON/DynamicKeysWithNestedRelationship.json
  206. +1 −1 Tests/Fixtures/JSON/DynamicKeysWithRelationship.json
  207. +1 −1 Tests/Fixtures/JSON/NakedEvents.json
  208. +1 −1 Tests/Fixtures/JSON/RailsUser.json
  209. +1 −1 Tests/Fixtures/JSON/error.json
  210. +1 −1 Tests/Fixtures/JSON/errors.json
  211. +1 −1 Tests/Fixtures/JSON/humans/1.json
  212. +1 −1 Tests/Fixtures/JSON/humans/all.json
  213. +1 −1 Tests/Fixtures/JSON/humans/with_to_one_relationship.json
  214. +1 −1 Tests/Fixtures/JSON/nested_user.json
  215. +1 −1 Tests/Fixtures/JSON/user.json
  216. +26 −26 Tests/Logic/CoreData/RKEntityByAttributeCacheTest.m
  217. +17 −17 Tests/Logic/CoreData/RKEntityCacheTest.m
  218. +5 −5 Tests/Logic/CoreData/RKFetchRequestMappingCacheTest.m
  219. +4 −4 Tests/Logic/CoreData/RKManagedObjectLoaderTest.m
  220. +40 −40 Tests/Logic/CoreData/RKManagedObjectMappingOperationTest.m
  221. +14 −14 Tests/Logic/CoreData/RKManagedObjectMappingTest.m
  222. +2 −2 Tests/Logic/CoreData/RKManagedObjectThreadSafeInvocationTest.m
  223. +9 −9 Tests/Logic/Network/RKClientTest.m
  224. +4 −4 Tests/Logic/Network/RKOAuthClientTest.m
  225. +8 −8 Tests/Logic/Network/RKParamsAttachmentTest.m
  226. +45 −45 Tests/Logic/Network/RKRequestTest.m
  227. +139 −139 Tests/Logic/Network/RKResponseTest.m
  228. +21 −21 Tests/Logic/ObjectMapping/RKObjectManagerTest.m
  229. +13 −13 Tests/Logic/ObjectMapping/RKObjectMappingNextGenTest.m
  230. +1 −1 Tests/Logic/ObjectMapping/RKObjectMappingOperationTest.m
  231. +2 −2 Tests/Logic/ObjectMapping/RKObjectMappingProviderTest.m
  232. +9 −9 Tests/Logic/ObjectMapping/RKObjectPaginatorTest.m
  233. +4 −4 Tests/Logic/ObjectMapping/RKParserRegistryTest.m
  234. +12 −12 Tests/Logic/Support/NSArray+RKAdditionsTest.m
  235. +1 −1 Tests/Logic/Support/RKCacheTest.m
  236. +3 −3 Tests/Logic/Support/RKDotNetDateFormatterTest.m
  237. +1 −1 Tests/Models/RKHuman.m
  238. +1 −1 Tests/Models/RKMappableAssociation.h
  239. +6 −6 Tests/Models/RKMappableObject.h
  240. +3 −3 Tests/Models/RKObjectMapperTestModel.h
  241. +3 −3 Tests/Models/RKSearchable.h
  242. +3 −3 Tests/Models/RKSearchable.m
  243. +1 −1 Tests/Models/RKTestAddress.m
  244. +1 −1 Tests/Models/RKTestUser.m
  245. +1 −1 Tests/RKTestEnvironment.h
View
6 Code/CoreData/CoreData.h
@@ -4,13 +4,13 @@
//
// Created by Blake Watters on 9/30/10.
// Copyright (c) 2009-2012 RestKit. All rights reserved.
-//
+//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
View
12 Code/CoreData/NSEntityDescription+RKAdditions.h
@@ -18,7 +18,7 @@ extern NSString * const RKEntityDescriptionPrimaryKeyAttributeUserInfoKey;
/**
The substitution variable used in predicateForPrimaryKeyAttribute.
-
+
**Value**: @"PRIMARY_KEY_VALUE"
@see predicateForPrimaryKeyAttribute
*/
@@ -47,21 +47,21 @@ extern NSString * const RKEntityDescriptionPrimaryKeyAttributeValuePredicateSubs
/**
Returns a cached predicate specifying that the primary key attribute is equal to the $PRIMARY_KEY_VALUE
substitution variable.
-
+
This predicate is cached to avoid parsing overhead during object mapping operations
and must be evaluated using [NSPredicate predicateWithSubstitutionVariables:]
-
- @return A cached predicate specifying the value of the primary key attribute is equal to the $PRIMARY_KEY_VALUE
+
+ @return A cached predicate specifying the value of the primary key attribute is equal to the $PRIMARY_KEY_VALUE
substitution variable.
*/
- (NSPredicate *)predicateForPrimaryKeyAttribute;
/**
Returns a predicate specifying that the value of the primary key attribute is equal to a given
- value. This predicate is constructed by evaluating the cached predicate returned by the
+ 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.
-
+
@return A predicate speciying that the value of the primary key attribute is equal to a given value.
*/
- (NSPredicate *)predicateForPrimaryKeyAttributeWithValue:(id)value;
View
4 Code/CoreData/NSEntityDescription+RKAdditions.m
@@ -35,7 +35,7 @@ - (NSString *)primaryKeyAttribute
// Fall back to the userInfo dictionary
if (! primaryKeyAttribute) {
primaryKeyAttribute = [self.userInfo valueForKey:RKEntityDescriptionPrimaryKeyAttributeUserInfoKey];
-
+
// If we have loaded from the user info, ensure we have a predicate
if (! [self predicateForPrimaryKeyAttribute]) {
[self setPredicateForPrimaryKeyAttribute:primaryKeyAttribute];
@@ -50,7 +50,7 @@ - (void)setPrimaryKeyAttribute:(NSString *)primaryKeyAttribute
objc_setAssociatedObject(self,
&primaryKeyAttributeKey,
primaryKeyAttribute,
- OBJC_ASSOCIATION_RETAIN);
+ OBJC_ASSOCIATION_RETAIN);
[self setPredicateForPrimaryKeyAttribute:primaryKeyAttribute];
}
View
8 Code/CoreData/NSManagedObject+ActiveRecord.h
@@ -28,13 +28,13 @@
@interface NSManagedObject (ActiveRecord)
/**
- * The NSEntityDescription for the Subclass
- * defaults to the subclass className, may be overridden
+ * The NSEntityDescription for the Subclass
+ * defaults to the subclass className, may be overridden
*/
+ (NSEntityDescription*)entity;
/**
- * Returns an initialized NSFetchRequest for the entity, with no predicate
+ * Returns an initialized NSFetchRequest for the entity, with no predicate
*/
+ (NSFetchRequest*)fetchRequest;
@@ -94,7 +94,7 @@
+ (NSUInteger)count DEPRECATED_ATTRIBUTE;
/**
- * Creates a new managed object and inserts it into the managedObjectContext.
+ * Creates a new managed object and inserts it into the managedObjectContext.
*/
+ (id)object;
View
610 Code/CoreData/NSManagedObject+ActiveRecord.m
@@ -52,84 +52,84 @@ @implementation NSManagedObject (ActiveRecord)
#pragma mark - RKManagedObject methods
+ (NSEntityDescription*)entity {
- NSString* className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
- return [NSEntityDescription entityForName:className inManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
+ NSString* className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
+ return [NSEntityDescription entityForName:className inManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
}
+ (NSFetchRequest*)fetchRequest {
- NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
- NSEntityDescription *entity = [self entity];
- [fetchRequest setEntity:entity];
- return 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];
- if (objects == nil) {
- RKLogError(@"Error: %@", [error localizedDescription]);
- }
- return objects;
+ 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 objectCount = [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:&error];
- if (objectCount == NSNotFound) {
- RKLogError(@"Error: %@", [error localizedDescription]);
- }
- return objectCount;
+ 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) {
- [mutableObjectArray addObjectsFromArray:[self objectsWithFetchRequest:fetchRequest]];
- }
- NSArray* objects = [NSArray arrayWithArray:mutableObjectArray];
- [mutableObjectArray release];
- return objects;
+ NSMutableArray* mutableObjectArray = [[NSMutableArray alloc] init];
+ for (NSFetchRequest* fetchRequest in fetchRequests) {
+ [mutableObjectArray addObjectsFromArray:[self objectsWithFetchRequest:fetchRequest]];
+ }
+ NSArray* objects = [NSArray arrayWithArray:mutableObjectArray];
+ [mutableObjectArray release];
+ return objects;
}
+ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest {
- [fetchRequest setFetchLimit:1];
- NSArray* objects = [self objectsWithFetchRequest:fetchRequest];
- if ([objects count] == 0) {
- return nil;
- } else {
- return [objects objectAtIndex:0];
- }
+ [fetchRequest setFetchLimit:1];
+ NSArray* objects = [self objectsWithFetchRequest:fetchRequest];
+ if ([objects count] == 0) {
+ return nil;
+ } else {
+ return [objects objectAtIndex:0];
+ }
}
+ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate {
- NSFetchRequest* fetchRequest = [self fetchRequest];
- [fetchRequest setPredicate:predicate];
- return [self objectsWithFetchRequest:fetchRequest];
+ NSFetchRequest* fetchRequest = [self fetchRequest];
+ [fetchRequest setPredicate:predicate];
+ return [self objectsWithFetchRequest:fetchRequest];
}
+ (id)objectWithPredicate:(NSPredicate*)predicate {
- NSFetchRequest* fetchRequest = [self fetchRequest];
- [fetchRequest setPredicate:predicate];
- return [self objectWithFetchRequest:fetchRequest];
+ NSFetchRequest* fetchRequest = [self fetchRequest];
+ [fetchRequest setPredicate:predicate];
+ return [self objectWithFetchRequest:fetchRequest];
}
+ (NSArray*)allObjects {
- return [self objectsWithPredicate:nil];
+ return [self objectsWithPredicate:nil];
}
+ (NSUInteger)count:(NSError**)error {
- NSFetchRequest* fetchRequest = [self fetchRequest];
- return [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:error];
+ NSFetchRequest* fetchRequest = [self fetchRequest];
+ return [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:error];
}
+ (NSUInteger)count {
- NSError *error = nil;
- return [self count:&error];
+ NSError *error = nil;
+ return [self count:&error];
}
+ (id)object {
- id object = [[self alloc] initWithEntity:[self entity] insertIntoManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
- return [object autorelease];
+ id object = [[self alloc] initWithEntity:[self entity] insertIntoManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
+ return [object autorelease];
}
- (BOOL)isNew {
@@ -160,91 +160,91 @@ + (NSManagedObjectContext*)currentContext; {
+ (void)setDefaultBatchSize:(NSUInteger)newBatchSize
{
- @synchronized(defaultBatchSize)
- {
- defaultBatchSize = [NSNumber numberWithUnsignedInteger:newBatchSize];
- }
+ @synchronized(defaultBatchSize)
+ {
+ defaultBatchSize = [NSNumber numberWithUnsignedInteger:newBatchSize];
+ }
}
+ (NSInteger)defaultBatchSize
{
- if (defaultBatchSize == nil)
- {
- [self setDefaultBatchSize:kActiveRecordDefaultBatchSize];
- }
- return [defaultBatchSize integerValue];
+ if (defaultBatchSize == nil)
+ {
+ [self setDefaultBatchSize:kActiveRecordDefaultBatchSize];
+ }
+ return [defaultBatchSize integerValue];
}
+ (void)handleErrors:(NSError *)error
{
- if (error)
- {
- NSDictionary *userInfo = [error userInfo];
- for (NSArray *detailedError in [userInfo allValues])
- {
- if ([detailedError isKindOfClass:[NSArray class]])
- {
- for (NSError *e in detailedError)
- {
- if ([e respondsToSelector:@selector(userInfo)])
- {
- RKLogError(@"Error Details: %@", [e userInfo]);
- }
- else
- {
- RKLogError(@"Error Details: %@", e);
- }
- }
- }
- else
- {
- RKLogError(@"Error: %@", detailedError);
- }
- }
- RKLogError(@"Error Domain: %@", [error domain]);
- RKLogError(@"Recovery Suggestion: %@", [error localizedRecoverySuggestion]);
- }
+ if (error)
+ {
+ NSDictionary *userInfo = [error userInfo];
+ for (NSArray *detailedError in [userInfo allValues])
+ {
+ if ([detailedError isKindOfClass:[NSArray class]])
+ {
+ for (NSError *e in detailedError)
+ {
+ if ([e respondsToSelector:@selector(userInfo)])
+ {
+ RKLogError(@"Error Details: %@", [e userInfo]);
+ }
+ else
+ {
+ RKLogError(@"Error Details: %@", e);
+ }
+ }
+ }
+ else
+ {
+ RKLogError(@"Error: %@", detailedError);
+ }
+ }
+ RKLogError(@"Error Domain: %@", [error domain]);
+ RKLogError(@"Recovery Suggestion: %@", [error localizedRecoverySuggestion]);
+ }
}
+ (NSArray *)executeFetchRequest:(NSFetchRequest *)request inContext:(NSManagedObjectContext *)context
{
- NSError *error = nil;
+ NSError *error = nil;
- NSArray *results = [context executeFetchRequest:request error:&error];
- [self handleErrors:error];
- return results;
+ NSArray *results = [context executeFetchRequest:request error:&error];
+ [self handleErrors:error];
+ return results;
}
+ (NSArray *)executeFetchRequest:(NSFetchRequest *)request
{
- return [self executeFetchRequest:request inContext:[self currentContext]];
+ return [self executeFetchRequest:request inContext:[self currentContext]];
}
+ (id)executeFetchRequestAndReturnFirstObject:(NSFetchRequest *)request inContext:(NSManagedObjectContext *)context
{
- [request setFetchLimit:1];
+ [request setFetchLimit:1];
- NSArray *results = [self executeFetchRequest:request inContext:context];
- if ([results count] == 0)
- {
- return nil;
- }
- return [results objectAtIndex:0];
+ NSArray *results = [self executeFetchRequest:request inContext:context];
+ if ([results count] == 0)
+ {
+ return nil;
+ }
+ return [results objectAtIndex:0];
}
+ (id)executeFetchRequestAndReturnFirstObject:(NSFetchRequest *)request
{
- return [self executeFetchRequestAndReturnFirstObject:request inContext:[self currentContext]];
+ return [self executeFetchRequestAndReturnFirstObject:request inContext:[self currentContext]];
}
#if TARGET_OS_IPHONE
+ (void)performFetch:(NSFetchedResultsController *)controller
{
- NSError *error = nil;
- if (![controller performFetch:&error])
- {
- [self handleErrors:error];
- }
+ NSError *error = nil;
+ if (![controller performFetch:&error])
+ {
+ [self handleErrors:error];
+ }
}
#endif
@@ -256,119 +256,119 @@ + (NSEntityDescription *)entityDescriptionInContext:(NSManagedObjectContext *)co
+ (NSEntityDescription *)entityDescription
{
- return [self entityDescriptionInContext:[self currentContext]];
+ return [self entityDescriptionInContext:[self currentContext]];
}
+ (NSArray *)propertiesNamed:(NSArray *)properties
{
- NSEntityDescription *description = [self entityDescription];
- NSMutableArray *propertiesWanted = [NSMutableArray array];
-
- if (properties)
- {
- NSDictionary *propDict = [description propertiesByName];
-
- for (NSString *propertyName in properties)
- {
- NSPropertyDescription *property = [propDict objectForKey:propertyName];
- if (property)
- {
- [propertiesWanted addObject:property];
- }
- else
- {
- RKLogError(@"Property '%@' not found in %@ properties for %@", propertyName, [propDict count], NSStringFromClass(self));
- }
- }
- }
- return propertiesWanted;
+ NSEntityDescription *description = [self entityDescription];
+ NSMutableArray *propertiesWanted = [NSMutableArray array];
+
+ if (properties)
+ {
+ NSDictionary *propDict = [description propertiesByName];
+
+ for (NSString *propertyName in properties)
+ {
+ NSPropertyDescription *property = [propDict objectForKey:propertyName];
+ if (property)
+ {
+ [propertiesWanted addObject:property];
+ }
+ else
+ {
+ RKLogError(@"Property '%@' not found in %@ properties for %@", propertyName, [propDict count], NSStringFromClass(self));
+ }
+ }
+ }
+ return propertiesWanted;
}
+ (NSArray *)sortAscending:(BOOL)ascending attributes:(id)attributesToSortBy, ...
{
- NSMutableArray *attributes = [NSMutableArray array];
-
- if ([attributesToSortBy isKindOfClass:[NSArray class]])
- {
- id attributeName;
- va_list variadicArguments;
- va_start(variadicArguments, attributesToSortBy);
- while ((attributeName = va_arg(variadicArguments, id))!= nil)
- {
- NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:attributeName ascending:ascending];
- [attributes addObject:sortDescriptor];
- [sortDescriptor release];
- }
- va_end(variadicArguments);
-
- }
- else if ([attributesToSortBy isKindOfClass:[NSString class]])
- {
- va_list variadicArguments;
- va_start(variadicArguments, attributesToSortBy);
- [attributes addObject:[[[NSSortDescriptor alloc] initWithKey:attributesToSortBy ascending:ascending] autorelease] ];
- va_end(variadicArguments);
- }
-
- return attributes;
+ NSMutableArray *attributes = [NSMutableArray array];
+
+ if ([attributesToSortBy isKindOfClass:[NSArray class]])
+ {
+ id attributeName;
+ va_list variadicArguments;
+ va_start(variadicArguments, attributesToSortBy);
+ while ((attributeName = va_arg(variadicArguments, id))!= nil)
+ {
+ NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:attributeName ascending:ascending];
+ [attributes addObject:sortDescriptor];
+ [sortDescriptor release];
+ }
+ va_end(variadicArguments);
+
+ }
+ else if ([attributesToSortBy isKindOfClass:[NSString class]])
+ {
+ va_list variadicArguments;
+ va_start(variadicArguments, attributesToSortBy);
+ [attributes addObject:[[[NSSortDescriptor alloc] initWithKey:attributesToSortBy ascending:ascending] autorelease] ];
+ va_end(variadicArguments);
+ }
+
+ return attributes;
}
+ (NSArray *)ascendingSortDescriptors:(id)attributesToSortBy, ...
{
- return [self sortAscending:YES attributes:attributesToSortBy];
+ return [self sortAscending:YES attributes:attributesToSortBy];
}
+ (NSArray *)descendingSortDescriptors:(id)attributesToSortyBy, ...
{
- return [self sortAscending:NO attributes:attributesToSortyBy];
+ return [self sortAscending:NO attributes:attributesToSortyBy];
}
+ (NSFetchRequest *)createFetchRequestInContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
- [request setEntity:[self entityDescriptionInContext:context]];
+ NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
+ [request setEntity:[self entityDescriptionInContext:context]];
- return request;
+ return request;
}
+ (NSFetchRequest *)createFetchRequest
{
- return [self createFetchRequestInContext:[self currentContext]];
+ return [self createFetchRequestInContext:[self currentContext]];
}
#pragma mark -
#pragma mark Number of Entities
+ (NSNumber *)numberOfEntitiesWithContext:(NSManagedObjectContext *)context
{
- NSError *error = nil;
- NSUInteger count = [context countForFetchRequest:[self createFetchRequestInContext:context] error:&error];
- [self handleErrors:error];
+ NSError *error = nil;
+ NSUInteger count = [context countForFetchRequest:[self createFetchRequestInContext:context] error:&error];
+ [self handleErrors:error];
- return [NSNumber numberWithUnsignedInteger:count];
+ return [NSNumber numberWithUnsignedInteger:count];
}
+ (NSNumber *)numberOfEntities
{
- return [self numberOfEntitiesWithContext:[self currentContext]];
+ return [self numberOfEntitiesWithContext:[self currentContext]];
}
+ (NSNumber *)numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context
{
- NSError *error = nil;
- NSFetchRequest *request = [self createFetchRequestInContext:context];
- [request setPredicate:searchTerm];
+ NSError *error = nil;
+ NSFetchRequest *request = [self createFetchRequestInContext:context];
+ [request setPredicate:searchTerm];
- NSUInteger count = [context countForFetchRequest:request error:&error];
- [self handleErrors:error];
-
- return [NSNumber numberWithUnsignedInteger:count];
+ NSUInteger count = [context countForFetchRequest:request error:&error];
+ [self handleErrors:error];
+
+ return [NSNumber numberWithUnsignedInteger:count];
}
+ (NSNumber *)numberOfEntitiesWithPredicate:(NSPredicate *)searchTerm;
{
- return [self numberOfEntitiesWithPredicate:searchTerm
- inContext:[self currentContext]];
+ return [self numberOfEntitiesWithPredicate:searchTerm
+ inContext:[self currentContext]];
}
+ (BOOL)hasAtLeastOneEntityInContext:(NSManagedObjectContext *)context
@@ -385,12 +385,12 @@ + (BOOL)hasAtLeastOneEntity
#pragma mark Reqest Helpers
+ (NSFetchRequest *)requestAll
{
- return [self createFetchRequestInContext:[self currentContext]];
+ return [self createFetchRequestInContext:[self currentContext]];
}
+ (NSFetchRequest *)requestAllInContext:(NSManagedObjectContext *)context
{
- return [self createFetchRequestInContext:context];
+ return [self createFetchRequestInContext:context];
}
+ (NSFetchRequest *)requestAllWhere:(NSString *)property isEqualTo:(id)value inContext:(NSManagedObjectContext *)context
@@ -435,45 +435,45 @@ + (NSFetchRequest *)requestFirstByAttribute:(NSString *)attribute withValue:(id)
+ (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self requestAllInContext:context];
+ NSFetchRequest *request = [self requestAllInContext:context];
- NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey:sortTerm ascending:ascending];
- [request setSortDescriptors:[NSArray arrayWithObject:sortBy]];
- [sortBy release];
+ NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey:sortTerm ascending:ascending];
+ [request setSortDescriptors:[NSArray arrayWithObject:sortBy]];
+ [sortBy release];
- return request;
+ return request;
}
+ (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending
{
- return [self requestAllSortedBy:sortTerm
- ascending:ascending
- inContext:[self currentContext]];
+ return [self requestAllSortedBy:sortTerm
+ ascending:ascending
+ inContext:[self currentContext]];
}
+ (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self requestAllInContext:context];
- [request setPredicate:searchTerm];
- [request setIncludesSubentities:NO];
- [request setFetchBatchSize:[self defaultBatchSize]];
+ NSFetchRequest *request = [self requestAllInContext:context];
+ [request setPredicate:searchTerm];
+ [request setIncludesSubentities:NO];
+ [request setFetchBatchSize:[self defaultBatchSize]];
- if (sortTerm != nil){
- NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey:sortTerm ascending:ascending];
- [request setSortDescriptors:[NSArray arrayWithObject:sortBy]];
- [sortBy release];
- }
+ if (sortTerm != nil){
+ NSSortDescriptor *sortBy = [[NSSortDescriptor alloc] initWithKey:sortTerm ascending:ascending];
+ [request setSortDescriptors:[NSArray arrayWithObject:sortBy]];
+ [sortBy release];
+ }
- return request;
+ return request;
}
+ (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm;
{
- NSFetchRequest *request = [self requestAllSortedBy:sortTerm
- ascending:ascending
- withPredicate:searchTerm
- inContext:[self currentContext]];
- return request;
+ NSFetchRequest *request = [self requestAllSortedBy:sortTerm
+ ascending:ascending
+ withPredicate:searchTerm
+ inContext:[self currentContext]];
+ return request;
}
@@ -482,44 +482,44 @@ + (NSFetchRequest *)requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)asce
+ (NSArray *)findAllInContext:(NSManagedObjectContext *)context
{
- return [self executeFetchRequest:[self requestAllInContext:context] inContext:context];
+ return [self executeFetchRequest:[self requestAllInContext:context] inContext:context];
}
+ (NSArray *)findAll
{
- return [self findAllInContext:[self currentContext]];
+ return [self findAllInContext:[self currentContext]];
}
+ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self requestAllSortedBy:sortTerm ascending:ascending inContext:context];
+ NSFetchRequest *request = [self requestAllSortedBy:sortTerm ascending:ascending inContext:context];
- return [self executeFetchRequest:request inContext:context];
+ return [self executeFetchRequest:request inContext:context];
}
+ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending
{
- return [self findAllSortedBy:sortTerm
- ascending:ascending
- inContext:[self currentContext]];
+ return [self findAllSortedBy:sortTerm
+ ascending:ascending
+ inContext:[self currentContext]];
}
+ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self requestAllSortedBy:sortTerm
- ascending:ascending
- withPredicate:searchTerm
- inContext:context];
+ NSFetchRequest *request = [self requestAllSortedBy:sortTerm
+ ascending:ascending
+ withPredicate:searchTerm
+ inContext:context];
- return [self executeFetchRequest:request inContext:context];
+ return [self executeFetchRequest:request inContext:context];
}
+ (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm
{
- return [self findAllSortedBy:sortTerm
- ascending:ascending
- withPredicate:searchTerm
- inContext:[self currentContext]];
+ return [self findAllSortedBy:sortTerm
+ ascending:ascending
+ withPredicate:searchTerm
+ inContext:[self currentContext]];
}
#pragma mark -
@@ -529,117 +529,117 @@ + (NSArray *)findAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending with
+ (NSFetchedResultsController *)fetchRequestAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
- NSString *cacheName = nil;
+ NSString *cacheName = nil;
#ifdef STORE_USE_CACHE
- cacheName = [NSString stringWithFormat:@"ActiveRecord-Cache-%@", NSStringFromClass(self)];
+ cacheName = [NSString stringWithFormat:@"ActiveRecord-Cache-%@", NSStringFromClass(self)];
#endif
- NSFetchRequest *request = [self requestAllSortedBy:sortTerm
- ascending:ascending
- withPredicate:searchTerm
- inContext:context];
+ NSFetchRequest *request = [self requestAllSortedBy:sortTerm
+ ascending:ascending
+ withPredicate:searchTerm
+ inContext:context];
- NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:request
- managedObjectContext:context
- sectionNameKeyPath:group
- cacheName:cacheName];
- return [controller autorelease];
+ NSFetchedResultsController *controller = [[NSFetchedResultsController alloc] initWithFetchRequest:request
+ managedObjectContext:context
+ sectionNameKeyPath:group
+ cacheName:cacheName];
+ return [controller autorelease];
}
+ (NSFetchedResultsController *)fetchRequestAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending
{
- return [self fetchRequestAllGroupedBy:group
- withPredicate:searchTerm
- sortedBy:sortTerm
- ascending:ascending
- inContext:[self currentContext]];
+ return [self fetchRequestAllGroupedBy:group
+ withPredicate:searchTerm
+ sortedBy:sortTerm
+ ascending:ascending
+ inContext:[self currentContext]];
}
+ (NSFetchedResultsController *)fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath inContext:(NSManagedObjectContext *)context
{
- NSFetchedResultsController *controller = [self fetchRequestAllGroupedBy:groupingKeyPath
- withPredicate:searchTerm
- sortedBy:sortTerm
- ascending:ascending
- inContext:context];
+ NSFetchedResultsController *controller = [self fetchRequestAllGroupedBy:groupingKeyPath
+ withPredicate:searchTerm
+ sortedBy:sortTerm
+ ascending:ascending
+ inContext:context];
- [self performFetch:controller];
- return controller;
+ [self performFetch:controller];
+ return controller;
}
+ (NSFetchedResultsController *)fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath
{
- return [self fetchAllSortedBy:sortTerm
- ascending:ascending
- withPredicate:searchTerm
- groupBy:groupingKeyPath
- inContext:[self currentContext]];
+ return [self fetchAllSortedBy:sortTerm
+ ascending:ascending
+ withPredicate:searchTerm
+ groupBy:groupingKeyPath
+ inContext:[self currentContext]];
}
+ (NSFetchedResultsController *)fetchRequest:(NSFetchRequest *)request groupedBy:(NSString *)group inContext:(NSManagedObjectContext *)context
{
- NSString *cacheName = nil;
+ NSString *cacheName = nil;
#ifdef STORE_USE_CACHE
- cacheName = [NSString stringWithFormat:@"ActiveRecord-Cache-%@", NSStringFromClass([self class])];
+ cacheName = [NSString stringWithFormat:@"ActiveRecord-Cache-%@", NSStringFromClass([self class])];
#endif
- NSFetchedResultsController *controller =
+ NSFetchedResultsController *controller =
[[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:context
sectionNameKeyPath:group
cacheName:cacheName];
[self performFetch:controller];
- return [controller autorelease];
+ return [controller autorelease];
}
+ (NSFetchedResultsController *)fetchRequest:(NSFetchRequest *)request groupedBy:(NSString *)group
{
- return [self fetchRequest:request
- groupedBy:group
- inContext:[self currentContext]];
+ return [self fetchRequest:request
+ groupedBy:group
+ inContext:[self currentContext]];
}
#endif
#pragma mark -
+ (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self createFetchRequestInContext:context];
- [request setPredicate:searchTerm];
+ NSFetchRequest *request = [self createFetchRequestInContext:context];
+ [request setPredicate:searchTerm];
- return [self executeFetchRequest:request
- inContext:context];
+ return [self executeFetchRequest:request
+ inContext:context];
}
+ (NSArray *)findAllWithPredicate:(NSPredicate *)searchTerm
{
- return [self findAllWithPredicate:searchTerm
- inContext:[self currentContext]];
+ return [self findAllWithPredicate:searchTerm
+ inContext:[self currentContext]];
}
+ (id)findFirstInContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self createFetchRequestInContext:context];
+ NSFetchRequest *request = [self createFetchRequestInContext:context];
- return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
+ return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
}
+ (id)findFirst
{
- return [self findFirstInContext:[self currentContext]];
+ return [self findFirstInContext:[self currentContext]];
}
+ (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self requestFirstByAttribute:attribute withValue:searchValue inContext:context];
+ NSFetchRequest *request = [self requestFirstByAttribute:attribute withValue:searchValue inContext:context];
- return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
+ return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
}
+ (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue
{
- return [self findFirstByAttribute:attribute
- withValue:searchValue
- inContext:[self currentContext]];
+ return [self findFirstByAttribute:attribute
+ withValue:searchValue
+ inContext:[self currentContext]];
}
+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm inContext:(NSManagedObjectContext *)context
@@ -656,85 +656,85 @@ + (id)findFirstWithPredicate:(NSPredicate *)searchTerm
+ (id)findFirstWithPredicate:(NSPredicate *)searchterm sortedBy:(NSString *)property ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self requestAllSortedBy:property ascending:ascending withPredicate:searchterm inContext:context];
+ NSFetchRequest *request = [self requestAllSortedBy:property ascending:ascending withPredicate:searchterm inContext:context];
- return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
+ return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
}
+ (id)findFirstWithPredicate:(NSPredicate *)searchterm sortedBy:(NSString *)property ascending:(BOOL)ascending
{
- return [self findFirstWithPredicate:searchterm
- sortedBy:property
- ascending:ascending
- inContext:[self currentContext]];
+ return [self findFirstWithPredicate:searchterm
+ sortedBy:property
+ ascending:ascending
+ inContext:[self currentContext]];
}
+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm andRetrieveAttributes:(NSArray *)attributes inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self createFetchRequestInContext:context];
- [request setPredicate:searchTerm];
+ NSFetchRequest *request = [self createFetchRequestInContext:context];
+ [request setPredicate:searchTerm];
- return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
+ return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
}
+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm andRetrieveAttributes:(NSArray *)attributes
{
- return [self findFirstWithPredicate:searchTerm
- andRetrieveAttributes:attributes
- inContext:[self currentContext]];
+ return [self findFirstWithPredicate:searchTerm
+ andRetrieveAttributes:attributes
+ inContext:[self currentContext]];
}
+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortBy ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context andRetrieveAttributes:(id)attributes, ...
{
- NSFetchRequest *request = [self requestAllSortedBy:sortBy
- ascending:ascending
- withPredicate:searchTerm
- inContext:context];
+ NSFetchRequest *request = [self requestAllSortedBy:sortBy
+ ascending:ascending
+ withPredicate:searchTerm
+ inContext:context];
- return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
+ return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
}
+ (id)findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortBy ascending:(BOOL)ascending andRetrieveAttributes:(id)attributes, ...
{
- return [self findFirstWithPredicate:searchTerm
- sortedBy:sortBy
- ascending:ascending
+ return [self findFirstWithPredicate:searchTerm
+ sortedBy:sortBy
+ ascending:ascending
inContext:[self currentContext]
- andRetrieveAttributes:attributes];
+ andRetrieveAttributes:attributes];
}
+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self createFetchRequestInContext:context];
+ NSFetchRequest *request = [self createFetchRequestInContext:context];
- [request setPredicate:[NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue]];
+ [request setPredicate:[NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue]];
- return [self executeFetchRequest:request inContext:context];
+ return [self executeFetchRequest:request inContext:context];
}
+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue
{
- return [self findByAttribute:attribute
- withValue:searchValue
- inContext:[self currentContext]];
+ return [self findByAttribute:attribute
+ withValue:searchValue
+ inContext:[self currentContext]];
}
+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
- NSPredicate *searchTerm = [NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue];
- NSFetchRequest *request = [self requestAllSortedBy:sortTerm ascending:ascending withPredicate:searchTerm inContext:context];
+ NSPredicate *searchTerm = [NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue];
+ NSFetchRequest *request = [self requestAllSortedBy:sortTerm ascending:ascending withPredicate:searchTerm inContext:context];
- return [self executeFetchRequest:request];
+ return [self executeFetchRequest:request];
}
+ (NSArray *)findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending
{
- return [self findByAttribute:attribute
- withValue:searchValue
- andOrderBy:sortTerm
- ascending:ascending
- inContext:[self currentContext]];
+ return [self findByAttribute:attribute
+ withValue:searchValue
+ andOrderBy:sortTerm
+ ascending:ascending
+ inContext:[self currentContext]];
}
+ (id)createInContext:(NSManagedObjectContext *)context
@@ -745,21 +745,21 @@ + (id)createInContext:(NSManagedObjectContext *)context
+ (id)createEntity
{
- NSManagedObject *newEntity = [self createInContext:[self currentContext]];
+ NSManagedObject *newEntity = [self createInContext:[self currentContext]];
- return newEntity;
+ return newEntity;
}
- (BOOL)deleteInContext:(NSManagedObjectContext *)context
{
- [context deleteObject:self];
- return YES;
+ [context deleteObject:self];
+ return YES;
}
- (BOOL)deleteEntity
{
- [self deleteInContext:[[self class] currentContext]];
- return YES;
+ [self deleteInContext:[[self class] currentContext]];
+ return YES;
}
+ (BOOL)truncateAllInContext:(NSManagedObjectContext *)context
@@ -780,25 +780,25 @@ + (BOOL)truncateAll
+ (NSNumber *)maxValueFor:(NSString *)property
{
- NSManagedObject *obj = [[self class] findFirstByAttribute:property
- withValue:[NSString stringWithFormat:@"max(%@)", property]];
+ NSManagedObject *obj = [[self class] findFirstByAttribute:property
+ withValue:[NSString stringWithFormat:@"max(%@)", property]];
- return [obj valueForKey:property];
+ return [obj valueForKey:property];
}
+ (id)objectWithMinValueFor:(NSString *)property inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [[self class] createFetchRequestInContext:context];
+ NSFetchRequest *request = [[self class] createFetchRequestInContext:context];
- NSPredicate *searchFor = [NSPredicate predicateWithFormat:@"SELF = %@ AND %K = min(%@)", self, property, property];
- [request setPredicate:searchFor];
+ NSPredicate *searchFor = [NSPredicate predicateWithFormat:@"SELF = %@ AND %K = min(%@)", self, property, property];
+ [request setPredicate:searchFor];
- return [[self class] executeFetchRequestAndReturnFirstObject:request inContext:context];
+ return [[self class] executeFetchRequestAndReturnFirstObject:request inContext:context];
}
+ (id)objectWithMinValueFor:(NSString *)property
{
- return [[self class] objectWithMinValueFor:property inContext:[self currentContext]];
+ return [[self class] objectWithMinValueFor:property inContext:[self currentContext]];
}
@end
View
38 Code/CoreData/RKEntityByAttributeCache.h
@@ -10,19 +10,19 @@
/**
Instances of RKEntityByAttributeCache provide an in-memory caching mechanism
- for managed objects instances of an entity in a managed object context with
- the value of one of the object's attributes acting as the cache key. When loaded,
- the cache will retrieve all instances of an entity from the store and build a
+ for managed objects instances of an entity in a managed object context with
+ the value of one of the object's attributes acting as the cache key. When loaded,
+ the cache will retrieve all instances of an entity from the store and build a
dictionary mapping values for the given cache key attribute to the managed object
ID for all objects matching the value. The cache can then be used to quickly retrieve
objects by attribute value for the cache key without executing another fetch request
against the managed object context. This can provide a large performance improvement
when a large number of objects are being retrieved using a particular attribute as
the key.
-
+
RKEntityByAttributeCache instances are used by the RKEntityCache to provide
caching for multiple entities at once.
-
+
@see RKEntityCache
*/
@interface RKEntityByAttributeCache : NSObject
@@ -33,7 +33,7 @@
/**
Initializes the receiver with a given entity, attribute, and managed object context.
-
+
@param entity The Core Data entity description for the managed objects being cached.
@param attributeName The name of an attribute within the cached entity that acts as the cache key.
@param managedObjectContext The managed object context the cache retrieves the cached
@@ -74,7 +74,7 @@
/**
Loads the cache by finding all instances of the configured entity and building
- an association between the value of the cached attribute's value and the
+ an association between the value of the cached attribute's value and the
managed object ID for the object.
*/
- (void)load;
@@ -103,7 +103,7 @@
/**
Returns the total number of cached objects with a given value for
the attribute acting as the cache key.
-
+
@param attributeValue The value for the cache key attribute to retrieve
a count of the objects with a matching value.
@return The number of objects in the cache with the given value for the cache
@@ -119,9 +119,9 @@
- (NSUInteger)countOfAttributeValues;
/**
- Returns a Boolean value that indicates whether a given object is present
+ Returns a Boolean value that indicates whether a given object is present
in the cache.
-
+
@param object An object.
@return YES if object is present in the cache, otherwise NO.
*/
@@ -130,27 +130,27 @@
/**
Returns a Boolean value that indicates whether one of more objects is present
in the cache with a given value of the cache key attribute.
-
+
@param attributeValue The value with which to check the cache for objects with
a matching value.
- @return YES if one or more objects with the given value for the cache key
+ @return YES if one or more objects with the given value for the cache key
attribute is present in the cache, otherwise NO.
*/
- (BOOL)containsObjectWithAttributeValue:(id)attributeValue;
/**
Returns the first object with a matching value for the cache key attribute.
-
+
@param attributeValue A value for the cache key attribute.
@return An object with the value of attribute matching attributeValue or nil.
*/
- (NSManagedObject *)objectWithAttributeValue:(id)attributeValue;
/**
Returns the collection of objects with a matching value for the cache key attribute.
-
+
@param attributeValue A value for the cache key attribute.
- @return An array of objects with the value of attribute matching attributeValue or
+ @return An array of objects with the value of attribute matching attributeValue or
an empty array.
*/
- (NSArray *)objectsWithAttributeValue:(id)attributeValue;
@@ -161,18 +161,18 @@
/**
Adds a managed object to the cache.
-
+
The object must be an instance of the cached entity.
-
+
@param object The managed object to add to the cache.
*/
- (void)addObject:(NSManagedObject *)object;
/**
Removes a managed object from the cache.
-
+
The object must be an instance of the cached entity.
-
+
@param object The managed object to remove from the cache.
*/
- (void)removeObject:(NSManagedObject *)object;
View
42 Code/CoreData/RKEntityByAttributeCache.m
@@ -39,15 +39,15 @@ - (id)initWithEntity:(NSEntityDescription *)entity attribute:(NSString *)attribu
_attribute = [attributeName retain];
_managedObjectContext = [context retain];
_monitorsContextForChanges = YES;
-
+
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(managedObjectContextDidChange:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:context];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(managedObjectContextDidSave:)
- name:NSManagedObjectContextDidSaveNotification
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(managedObjectContextDidSave:)
+ name:NSManagedObjectContextDidSaveNotification
object:context];
#if TARGET_OS_IPHONE
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -56,19 +56,19 @@ - (id)initWithEntity:(NSEntityDescription *)entity attribute:(NSString *)attribu
object:nil];
#endif
}
-
+
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
-
+
[_entity release];
[_attribute release];
[_managedObjectContext release];
[_attributeValuesToObjectIDs release];
-
+
[super dealloc];
}
@@ -92,34 +92,34 @@ - (BOOL)shouldCoerceAttributeToString:(NSString *)attributeValue
if ([attributeValue isKindOfClass:[NSString class]] || [attributeValue isEqual:[NSNull null]]) {
return NO;
}
-
+
Class attributeType = [[RKObjectPropertyInspector sharedInspector] typeForProperty:self.attribute ofEntity:self.entity];
return [attributeType instancesRespondToSelector:@selector(stringValue)];
}
- (void)load
{
- RKLogInfo(@"Loading entity cache for Entity '%@' by attribute '%@'", self.entity.name, self.attribute);
+ RKLogInfo(@"Loading entity cache for Entity '%@' by attribute '%@'", self.entity.name, self.attribute);
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:self.entity];
[fetchRequest setResultType:NSManagedObjectIDResultType];
-
+
NSError *error = nil;
NSArray *objectIDs = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (error) {
RKLogError(@"Failed to load entity cache: %@", error);
return;
}
[fetchRequest release];
-
+
self.attributeValuesToObjectIDs = [NSMutableDictionary dictionaryWithCapacity:[objectIDs count]];
for (NSManagedObjectID *objectID in objectIDs) {
NSError *error = nil;
NSManagedObject *object = [self.managedObjectContext existingObjectWithID:objectID error:&error];
if (! object && error) {
RKLogError(@"Failed to retrieve managed object with ID %@: %@", objectID, error);
}
-
+
[self addObject:object];
}
}
@@ -160,7 +160,7 @@ - (NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID {
RKLogError(@"Failed to retrieve managed object with ID %@. Error %@\n%@", objectID, [error localizedDescription], [error userInfo]);
return nil;
}
-
+
return object;
}
@@ -174,10 +174,10 @@ - (NSArray *)objectsWithAttributeValue:(id)attributeValue
NSManagedObject *object = [self objectWithID:objectID];
if (object) [objects addObject:object];
}
-
+
return objects;
}
-
+
return [NSArray array];
}
@@ -197,7 +197,7 @@ - (void)addObject:(NSManagedObject *)object
} else {
objectIDs = [NSMutableArray arrayWithObject:objectID];
}
-
+
if (nil == self.attributeValuesToObjectIDs) self.attributeValuesToObjectIDs = [NSMutableDictionary dictionary];
[self.attributeValuesToObjectIDs setValue:objectIDs forKey:attributeValue];
} else {
@@ -241,22 +241,22 @@ - (BOOL)containsObject:(NSManagedObject *)object
- (void)managedObjectContextDidChange:(NSNotification *)notification
{
if (self.monitorsContextForChanges == NO) return;
-
+
NSDictionary *userInfo = notification.userInfo;
NSSet *insertedObjects = [userInfo objectForKey:NSInsertedObjectsKey];
NSSet *updatedObjects = [userInfo objectForKey:NSUpdatedObjectsKey];
NSSet *deletedObjects = [userInfo objectForKey:NSDeletedObjectsKey];
RKLogTrace(@"insertedObjects=%@, updatedObjects=%@, deletedObjects=%@", insertedObjects, updatedObjects, deletedObjects);
-
+
NSMutableSet *objectsToAdd = [NSMutableSet setWithSet:insertedObjects];
[objectsToAdd unionSet:updatedObjects];
-
+
for (NSManagedObject *object in objectsToAdd) {
if ([object.entity isEqual:self.entity]) {
[self addObject:object];
}
}
-
+
for (NSManagedObject *object in deletedObjects) {
if ([object.entity isEqual:self.entity]) {
[self removeObject:object];
View
30 Code/CoreData/RKEntityCache.h
@@ -9,14 +9,14 @@
#import <CoreData/CoreData.h>
@class RKEntityByAttributeCache;
-
+
/**
- Instances of RKInMemoryEntityCache provide an in-memory caching mechanism for
+ Instances of RKInMemoryEntityCache provide an in-memory caching mechanism for
objects in a Core Data managed object context. Managed objects can be cached by
- attribute for fast retrieval without repeatedly hitting the Core Data persistent store.
+ attribute for fast retrieval without repeatedly hitting the Core Data persistent store.
This can provide a substantial speed advantage over issuing fetch requests
in cases where repeated look-ups of the same data are performed using a small set
- of attributes as the query key. Internally, the cache entries are maintained as
+ of attributes as the query key. Internally, the cache entries are maintained as
references to the NSManagedObjectID of corresponding cached objects.
*/
@interface RKEntityCache : NSObject
@@ -27,7 +27,7 @@
/**
Initializes the receiver with a managed object context containing the entity instances to be cached.
-
+
@param context The managed object context containing objects to be cached.
@returns self, initialized with context.
*/
@@ -44,15 +44,15 @@
/**
Caches all instances of an entity using the value for an attribute as the cache key.
-
+
@param entity The entity to cache all instances of.
@param attributeName The attribute to cache the instances by.
*/
- (void)cacheObjectsForEntity:(NSEntityDescription *)entity byAttribute:(NSString *)attributeName;
/**
Returns a Boolean value indicating if all instances of an entity have been cached by a given attribute name.
-
+
@param entity The entity to check the cache status of.
@param attributeName The attribute to check the cache status with.
@return YES if the cache has been loaded with instances with the given attribute, else NO.
@@ -61,7 +61,7 @@
/**
Retrieves the first cached instance of a given entity where the specified attribute matches the given value.
-
+
@param entity The entity to search the cache for instances of.
@param attributeName The attribute to search the cache for matches with.
@param attributeValue The value of the attribute to return a match for.
@@ -72,7 +72,7 @@
/**
Retrieves all cached instances of a given entity where the specified attribute matches the given value.
-
+
@param entity The entity to search the cache for instances of.
@param attributeName The attribute to search the cache for matches with.
@param attributeValue The value of the attribute to return a match for.
@@ -87,7 +87,7 @@
/**
Retrieves the underlying entity attribute cache for a given entity and attribute.
-
+
@param entity The entity to retrieve the entity attribute cache object for.
@param attributeName The attribute to retrieve the entity attribute cache object for.
@return The entity attribute cache for the given entity and attribute, or nil if none was found.
@@ -96,11 +96,11 @@
/**
Retrieves all entity attributes caches for a given entity.
-
+
@param entity The entity to retrieve the collection of entity attribute caches for.
@return An array of entity attribute cache objects for the given entity or an empty array if none were found.
*/
-- (NSArray *)attributeCachesForEntity:(NSEntityDescription *)entity;
+- (NSArray *)attributeCachesForEntity:(NSEntityDescription *)entity;
///-----------------------------------------------------------------------------
// @name Managing the Cache
@@ -109,23 +109,23 @@
/**
Flushes the entity cache by sending a flush message to each entity attribute cache
contained within the receiver.
-
+
@see [RKEntityByAttributeCache flush]
*/
- (void)flush;
/**
Adds a given object to all entity attribute caches for the object's entity contained
within the receiver.
-
+
@param object The object to add to the appropriate entity attribute caches.
*/
- (void)addObject:(NSManagedObject *)object;
/**
Removed a given object from all entity attribute caches for the object's entity contained
within the receiver.
-
+
@param object The object to remove from the appropriate entity attribute caches.
*/
- (void)removeObject:(NSManagedObject *)object;
View
10 Code/CoreData/RKEntityCache.m
@@ -26,7 +26,7 @@ - (id)initWithManagedObjectContext:(NSManagedObjectContext *)context
_managedObjectContext = [context retain];
_attributeCaches = [[NSMutableSet alloc] init];
}
-
+
return self;
}
@@ -73,7 +73,7 @@ - (NSManagedObject *)objectForEntity:(NSEntityDescription *)entity withAttribute
if (attributeCache) {
return [attributeCache objectWithAttributeValue:attributeValue];
}
-
+
return nil;
}
@@ -85,7 +85,7 @@ - (NSArray *)objectsForEntity:(NSEntityDescription *)entity withAttribute:(NSStr
if (attributeCache) {
return [attributeCache objectsWithAttributeValue:attributeValue];
}
-
+
return [NSSet set];
}
@@ -98,7 +98,7 @@ - (RKEntityByAttributeCache *)attributeCacheForEntity:(NSEntityDescription *)ent
return cache;
}
}
-
+
return nil;
}
@@ -111,7 +111,7 @@ - (NSSet *)attributeCachesForEntity:(NSEntityDescription *)entity
[set addObject:cache];
}
}
-
+
return [NSSet setWithSet:set];
}
View
6 Code/CoreData/RKFetchRequestManagedObjectCache.m
@@ -28,7 +28,7 @@ - (NSManagedObject *)findInstanceOfEntity:(NSEntityDescription *)entity
NSAssert(primaryKeyAttribute, @"Cannot find existing managed object instance without mapping that defines a primaryKeyAttribute");
NSAssert(primaryKeyValue, @"Cannot find existing managed object by primary key without a value");
NSAssert(managedObjectContext, @"Cannot find existing managed object with a context");
-
+
id searchValue = primaryKeyValue;
Class type = [[RKObjectPropertyInspector sharedInspector] typeForProperty:primaryKeyAttribute ofEntity:entity];
if (type && ([type isSubclassOfClass:[NSString class]] && NO == [primaryKeyValue isKindOfClass:[NSString class]])) {
@@ -38,7 +38,7 @@ - (NSManagedObject *)findInstanceOfEntity:(NSEntityDescription *)entity
searchValue = [NSNumber numberWithDouble:[(NSString *)primaryKeyValue doubleValue]];
}
}
-
+
// Use cached predicate if primary key matches
NSPredicate *predicate = nil;
if ([entity.primaryKeyAttribute isEqualToString:primaryKeyAttribute]) {
@@ -54,7 +54,7 @@ - (NSManagedObject *)findInstanceOfEntity:(NSEntityDescription *)entity
NSArray *objects = [NSManagedObject executeFetchRequest:fetchRequest inContext:managedObjectContext];
RKLogDebug(@"Found objects '%@' using fetchRequest '%@'", objects, fetchRequest);
[fetchRequest release];
-
+
NSManagedObject *object = nil;
if ([objects count] > 0) {
object = [objects objectAtIndex:0];
View
6 Code/CoreData/RKInMemoryManagedObjectCache.m
@@ -28,15 +28,15 @@ - (RKEntityCache *)cacheForEntity:(NSEntityDescription *)entity inManagedObjectC
contextDictionary = [NSMutableDictionary dictionaryWithCapacity:1];
[[[NSThread currentThread] threadDictionary] setObject:contextDictionary forKey:RKInMemoryObjectManagedObjectCacheThreadDictionaryKey];
}
- NSNumber *hashNumber = [NSNumber numberWithUnsignedInteger:[managedObjectContext hash]];
+ NSNumber *hashNumber = [NSNumber numberWithUnsignedInteger:[managedObjectContext hash]];
RKEntityCache *entityCache = [contextDictionary objectForKey:hashNumber];
if (! entityCache) {
RKLogInfo(@"Creating thread-local entity cache for managed object context: %@", managedObjectContext);
entityCache = [[RKEntityCache alloc] initWithManagedObjectContext:managedObjectContext];
[contextDictionary setObject:entityCache forKey:hashNumber];
[entityCache release];
}
-
+
return entityCache;
}
@@ -52,7 +52,7 @@ - (NSManagedObject *)findInstanceOfEntity:(NSEntityDescription *)entity
RKEntityByAttributeCache *attributeCache = [entityCache attributeCacheForEntity:entity attribute:primaryKeyAttribute];
RKLogTrace(@"Cached %ld objects", (long) [attributeCache count]);
}
-
+
return [entityCache objectForEntity:entity withAttribute:primaryKeyAttribute value:primaryKeyValue];
}
View
6 Code/CoreData/RKManagedObjectCaching.h
@@ -38,21 +38,21 @@
/**
Tells the receiver that an object was fetched and should be added to the cache.
-
+
@param object The object that was fetched from a managed object context.
*/
- (void)didFetchObject:(NSManagedObject *)object;
/**
Tells the receiver that an object was created and should be added to the cache.
-
+
@param object The object that was created in a managed object context.
*/
- (void)didCreateObject:(NSManagedObject *)object;
/**
Tells the receiver that an object was deleted and should be removed to the cache.
-
+
@param object The object that was deleted from a managed object context.
*/
- (void)didDeleteObject:(NSManagedObject *)object;
View
10 Code/CoreData/RKManagedObjectLoader.h
@@ -4,13 +4,13 @@
//
// Created by Blake Watters on 2/13/11.
// Copyright (c) 2009-2012 RestKit. All rights reserved.