Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ScheduleRequest with completionHandler
- (void) scheduleRequest:(id<SODataRequestParam>)request completionHandler:(void(^)(NSArray *entities, id<SODataRequestExecution>requestExecution, NSError *error))completion
NSString *finishedSubscription = [NSString stringWithFormat:@"%@.%@", kRequestDelegateFinished, request];
[[NSNotificationCenter defaultCenter] addObserverForName:finishedSubscription
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
id<SODataRequestExecution>requestExecution = note.object;
id<SODataResponse> response = requestExecution.response;
id<SODataResponseSingle> respSingle = (id<SODataResponseSingle>) response;
id<SODataPayload> p = respSingle.payload;
SODataEntitySetDefault *entities = (id<SODataEntitySet>)p;
// return (NSArray *entities, id<SODataRequestExecution>requestExecution, NSError *error)
completion(entities.entities, requestExecution, nil);
}];
[self.store scheduleRequest:request delegate:self];
}
- (void) requestFinished:(id<SODataRequestExecution>)requestExecution
{
// build notification tag for this request
NSString *finishedSubscription = [NSString stringWithFormat:@"%@.%@", kRequestDelegateFinished, requestExecution.request];
// send notification for the finished request
[[NSNotificationCenter defaultCenter] postNotificationName:finishedSubscription object:requestExecution];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment