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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With