Last active
August 29, 2015 14:06
-
-
Save sstadelman/074f97695ba11bd8f48f to your computer and use it in GitHub Desktop.
ScheduleRequest with completionHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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