I hate blocks. They are meant to make the code more concise, but I couldn’t find anything more ugly. For instance, with AFNetworking:
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
requestsuccess:^(NSURLRequest *request, NSURLResponse *response, id JSON) {
// Some
// very
// long
// (and as ugly as blocks)
// processing
}
failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON )) {
// Failure code
}]
Something like this would have been much better:
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
requestsuccess:@selector(requestSuccess:response:json:)
failure:@selector(requestSuccess:response:error:)]
So, is it possible to use method’s selectors as blocks ? If not, how can I make the block code better ?
It annoys me, as these blocks seems to be the future of objective-c programming and they are just NOT readable.
So you think the block construct makes the code harder to read?
I think they can sometimes make things easier to understand, especially in asynchronous contexts like in networking code.
To make it easier to read you can assign blocks to variables. (Indeed blocks are objective-c objects.)
Example:
You can also call a single handler method inside the block to keep it small.