How can i specify the return types in GCD blocks? Here I want to return my result as NSData …
- (NSData *)returnData:(NSString *)urlString{
dispatch_queue_t concurrentQueue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_sync(concurrentQueue, ^{ // here return type showing error
NSString *strUrl = urlString;
if([strUrl length] == 0)
return nil; // from this point i want to stop the execution of the block and return nil .
// otherwise only continue the left operations
});
}
The block’s format (parameters/return type) are specified in the function’s signature. In this case,
dispatch_syncuses a block with no return type and no parameters. If you want further variables to work with you need to declare them outside the block, as in the code above.