Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclass AFHTTPRequestOperationManager?

I find myself repeating a lot of code using AFHTTPRequestOperationManager throughout my code, so I was thinking about subclassing it, so I can set it up once as a singleton, and put all the code in the subclass, as opposed to have it spread out through my project. However on the NSHipster episode on AFNetworking 2.0 (http://nshipster.com/afnetworking-2/), it says:

The main difference in 2.0 is that you'll actually use this class directly, rather than subclass it, for reasons explained in the "Serialization" section.

Since AFNetworking and NSHipster have the same author, I regard this a valid argument.

So my question is, do people subclass AFHTTPRequestOperationManager in order to have most network code in one class, or am I overlooking something in the use of the framework?

like image 720
koen Avatar asked Nov 01 '22 08:11

koen


1 Answers

This is how I solved it.

I created a new MyDBClient object, of which the AFHTTPRequestOperationManager is a property. MyDBClient is a singleton class. I then call my MyDBClient from my view controllers and let that setup the operation manager and start the request. Advantage of this is also that it is easier to switch between AFHTTPRequestOperationManager (pre iOS7) and AFHTTPPSessionManager (iOS7).

like image 190
koen Avatar answered Nov 15 '22 05:11

koen