2
votes

In my app I have got ViewControllers->Business Logic Layer(BLL)->Data Access Layer(DAL)->(HttpApi) OR (SQLiteApi)

In my HttpApi class I am using ASIHttpRequest with asynchronous requests.

Requests come from the ViewController initially and all the way up through the above layers.

I would like to be able to "inject" the result from the Async request back into this chain so that it can be returned all the way back down to the ViewController and be processed by the intermediate layers on the way.

I have a feeling that it's Delegates I need but i'm not really sure what to implement.

EDIT: I think I may need to develop a callback chain that goes from HTTPAPI all the way back to the view controller.. I'll need to use delegates.

So, view controller conforms to BLL delegate and BLL conforms to DAL Delegate and so on..

1

1 Answers

4
votes

I would broadcast the request upon receiving a response using a notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"requestFinished" object:request];

Then any of your classes can listen as follows:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestFinished:) name:@"requestFinished" object:nil];

- (void)requestFinished:(NSNotification*)notification {
    ASIHTTPRequest *request = (ASIHTTPRequest*)[notification object];

    if ([[[request URL] absoluteString] isEqualToString:expectedURL]) {
        NSString *responseString = [request responseString];
        NSLog(@"RESPONSE %@", responseString);
    }
}