HttpClient.h

@interface HttpClient : NSObject
{
void (^finishLoadingHandler)(NSString* response);
}

– (void) OnFinishLoading:(void(^)(NSString*))response;

HttpClient.m

– (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *stringData = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
finishLoadingHandler(stringData); //maybe you should put nil check here
}

– (void) OnFinishLoading:(void(^)(NSString*))response
{
finishLoadingHandler=[response copy];
}

Controller.m
HttpClient *httpClient=[[HttpClient alloc]init];
[httpClient OnFinishLoading:^(NSString* response){
NSLog(@”%@”, response);
}];

You keep in mind that i’m still learning objective c
this block stuff on objective c
is similiar with event based programming on c#

void (^finishLoadingHandler)(NSString* response);
//this is your function handler

– (void) OnFinishLoading:(void(^)(NSString*))response;
//this is a method to assign your callback

I don’t put too much objective c code to avoid confusing
but i believe people who came from c# will understand these code sample
good luck!

Advertisements