I’m looking at the source code for AFNetworking (and am noob at Objective-C and AFNetworking) and am trying to understand some inherited code. It looks like they are blocks that return nothing, pass in an AFHTTPRequestOperation and either the response or the NSError. Is this a block definition? What does the success / failure at the end signify? I’m thinking it’s something like success:MyParam(NSString *)my_param. Just like a single sentence would suffice.
- (void)getPath:(NSString *)path
parameters:(NSDictionary *)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
Any help is appreciated. Thx in advance
The
successandfailureparameters are blocks, an extension to the C programming language by Apple. A block is very similar to an anonymous function pointer.It plays the role of a drop-in call-back function in this scenario. If the path were successfully got,
successcall-back would be invoked, or thefailurecall-back would be invoked.The signature specified what parameters these call-back blocks should accept, respectively. The actual values of these parameters would be provided by this AFNetworking call.