我讨厌积木。它们旨在使代码更简洁,但我找不到更难看的东西。例如,使用 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
}]
这样的事情会好得多:
AFJSONRequestOperation* operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
requestsuccess:@selector(requestSuccess:response:json:)
failure:@selector(requestSuccess:response:error:)]
那么,是否可以将方法的选择器用作块?如果没有,我怎样才能使块代码更好?
这让我很恼火,因为这些块似乎是 Objective-C 编程的未来,它们只是不可读。