Files
RestKit/Code/ObjectMapping/RKMappingOperationQueue.m
Blake Watters 70c73f2981 Fixed issue with order dependence in Core Data connections. fixes #173
Since OM 2.0 connection of relationships happened during the object mapping operation
instead of aggregately at the end of the process. In this commit, we have introduced a lightweight
queue for deferring portions of the mapping operation until a larger aggregate mapping has completed.

The changes are as follows:
* Introduced RKMappingOperationQueue for queueing portions of mapping. This is a synchronous queue modeled off
of NSOperationQueue that does NOT use threading (for Core Data friendliness).
* RKObjectMappingOperation now has a RKMappingOperationQueue queue property that defaults to nil
* RKObjectMappingOperation instances built via RKObjectMapper will has a mapping operation queue
assigned to the property.
* If a queue is present, RKManagedObjectMappingOperation will use it to defer the connection of relationships.
* At the end of an RKObjectMapper process, the mapping operation queue used by all mapping operations created
during the process will be executed. This allows all relationships to be connected after all object creation
has completed.

The queue is general purpose, though currently only used for the connection of relationships.
2011-09-20 12:02:50 -04:00

51 lines
967 B
Objective-C

//
// RKMappingOperationQueue.m
// RestKit
//
// Created by Blake Watters on 9/20/11.
// Copyright (c) 2011 RestKit. All rights reserved.
//
#import "RKMappingOperationQueue.h"
@implementation RKMappingOperationQueue
- (id)init {
self = [super init];
if (self) {
_operations = [NSMutableArray new];
}
return self;
}
- (void)dealloc {
[_operations release];
[super dealloc];
}
- (void)addOperation:(NSOperation *)op {
[_operations addObject:op];
}
- (void)addOperationWithBlock:(void (^)(void))block {
NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:block];
[_operations addObject:blockOperation];
}
- (NSArray *)operations {
return [NSArray arrayWithArray:_operations];
}
- (NSUInteger)operationCount {
return [_operations count];
}
- (void)waitUntilAllOperationsAreFinished {
for (NSOperation *operation in _operations) {
[operation start];
}
}
@end