You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear Blake Watters,
first i want to say thanks for this great Tool!
Below 2 little patches for RestKit, which you might want to consider:
1. Now that we have a CoreData caching mechanism, we actually also want to use it (esp. in relationship mappings). This little patch made the difference between unusable and usable for my little app.
--- RestKit/Code/CoreData/RKManagedObjectMappingOperation.m
+++ RestKit/Code/CoreData/RKManagedObjectMappingOperation.m
@@ -23,6 +23,7 @@
#import "NSManagedObject+ActiveRecord.h"
#import "RKDynamicObjectMappingMatcher.h"
#import "RKLog.h"
+#import "RKManagedObjectStore.h"
// Set Logging Component
#undef RKLogComponent
@@ -75,10 +76,16 @@
relatedObject = [NSSet setWithArray:objects];
} else {
RKLogTrace(@"Connecting has-one relationship at keyPath '%@' to object with primaryKey attribute '%@'", relationshipName, primaryKeyAttributeOfRelatedObject);
- NSFetchRequest *fetchRequest = [NSManagedObject requestFirstByAttribute:primaryKeyAttributeOfRelatedObject withValue:valueOfLocalPrimaryKeyAttribute inContext:[self.destinationObject managedObjectContext]];
- fetchRequest.entity = objectMapping.entity;
- NSArray *objects = [NSManagedObject executeFetchRequest:fetchRequest inContext:[self.destinationObject managedObjectContext]];
- relatedObject = [objects lastObject];
+ relatedObject = [objectMapping.objectStore.cacheStrategy findInstanceOfEntity:objectMapping.entity
+ withPrimaryKeyAttribute:primaryKeyAttributeOfRelatedObject
+ value:valueOfLocalPrimaryKeyAttribute
+ inManagedObjectContext:[self.destinationObject managedObjectContext]];
+ if (relatedObject == nil) {
+ NSFetchRequest *fetchRequest = [NSManagedObject requestFirstByAttribute:primaryKeyAttributeOfRelatedObject withValue:valueOfLocalPrimaryKeyAttribute inContext:[self.destinationObject managedObjectContext]];
+ fetchRequest.entity = objectMapping.entity;
+ NSArray *objects = [NSManagedObject executeFetchRequest:fetchRequest inContext:[self.destinationObject managedObjectContext]];
+ relatedObject = [objects lastObject];
+ }
}
if (relatedObject) {
RKLogDebug(@"Connected relationship '%@' to object with primary key value '%@': %@", relationshipName, valueOfLocalPrimaryKeyAttribute, relatedObject);
2. I'm starting several RestKit requests from a background thread and this patch made it actually possible to do so. I know that RKRequestQueue is not totally thread safe, but for me this worked fine.
--- RestKit/Code/Network/RKRequestQueue.m
+++ RestKit/Code/Network/RKRequestQueue.m
@@ -382,7 +382,9 @@
}
- (BOOL)containsRequest:(RKRequest*)request {
- return [_requests containsObject:request];
+ @synchronized(self) {
+ return [_requests containsObject:request];
+ }
}
- (void)cancelRequest:(RKRequest*)request loadNext:(BOOL)loadNext {
Feel free to use these patches.
Kind regards,
Frank Heldt
The text was updated successfully, but these errors were encountered:
The second one is actually a potential fix to a race condition I've experienced when launching requests from a background thread as well, so I will let you know if it solves my problem.
These came through via e-mail:
The text was updated successfully, but these errors were encountered: