I have created a block void function wich is using AFNetworking library. This function is used for GET
request and uses like so.
[Mics getRequestBLOCK:clientsUrlStr BlockRequest:^(NSString *response) {
//use response here
}];
Everything work fine, but I really get a headache when I use this block in a function that need return a value, for instance.
+ (NSArray*)OnlineClients
{
NSString *clientsUrlStr = [NSString stringWithFormat:@"%@/sinch/clients", ROOT_URL];
__block NSArray *clients = [[NSArray alloc] init];
[Mics getRequestBLOCK:clientsUrlStr BlockRequest:^(NSString *response) {
clients = [response componentsSeparatedByString: @","];
}];
return clients;
}
OnlineClients
array function always return 0 item because request block is not finished with completion.
So, how can I wait for block completion to get response request for return in a function?
I have been searching various topics in StackOverflow and google but can't found any solution.
Please help.