Restkit 2.0 cancellation - any hidden issues related to this?

I just started with a code base that uses RestKit 2.0.

One of the problems with the codebase is the abundance of network calls that are difficult to undo.

I see that some network methods can easily return work to the caller so that the caller can undo them. However, the interface doesn't support this easily. Has anyone tried to write my own category to reveal the return of these operations?

For example,

- (void)getObjectsAtPath:(NSString *)path
              parameters:(NSDictionary *)parameters
                 success:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
                 failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure
{
    NSParameterAssert(path);
    RKObjectRequestOperation *operation = [self appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:path parameters:parameters];
    [operation setCompletionBlockWithSuccess:success failure:failure];
    [self enqueueObjectRequestOperation:operation];
}

      

It might look like this:

- (NSOperation *)getObjectsAtPath:(NSString *)path
              parameters:(NSDictionary *)parameters
                 success:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success
                 failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure
{
    NSParameterAssert(path);
    RKObjectRequestOperation *operation = [self appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:path parameters:parameters];
    [operation setCompletionBlockWithSuccess:success failure:failure];
    [self enqueueObjectRequestOperation:operation];
    return operation;
}

      

Please let me know if anyone tried this and ran into problems.

+3


source to share


1 answer


This is not the only operation involved in the process. It deals with the networking aspect, but not the mapping. This does not mean that it is impossible, but it is not necessarily as easy as you think.



RKObjectManager

provides an interface for canceling in-flight operations based on a request rather than a specific operation that is more appropriate to use.

0


source







All Articles