AFNetworking/AFNetworking — Issue #188: Feature Request for AFHTTPClient Builder Block
Author: esummers
Created: 2012-01-23 17:19:43+00:00
State: open

I noticed you are using a the builder pattern via a block in the init method:

- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
constructingBodyWithBlock:(void (^)(id formData))block;

I have been using this pattern for awhile in my code. I thought I'd suggest a slight variation that I think helps provide better encapsilation. I like to put my builder methods in a protocol and then setup the block like this:

- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
constructingBodyWithBlock:(void (^)(id builder, id formData))block;

Then specify the protocol in a class extension on AFHTTPClient so the methods remain hidden to the user. The init method would expose the methods by calling the block with "self" as the first parameter like this:
builder(self, formData);

I hope this helps. Thanks for the great framework.