4 ms·
I haven't reviewed the implementation, but the API alone appears to be a significant improvement over the previously available options. However, the use of non
by nupark2 15y ago
I haven't reviewed the implementation, but the API alone appears to be a significant improvement over the previously available options.
However, the use of non-prefixed category methods (monkey-patching) is an inappropriate design choice, given the fact that the likelihood of conflict is actually higher than 0 when using non-prefixed category methods.
Let's say you were doing a gradual migration from ASIHTTP -- you'd have a non-deterministic conflict on the -[UIImageView setImageWithURL:] category method.
Unfortunately -- and despite repeated advisements to not do so by Apple engineers and others -- AFNetworking isn't the only library to add such a category method, and in fact, a number of libraries and third-party code add different, conflicting -[UIImageView setImageWithURL:] category methods. It's not too hard to wind up with a conflict.
Category methods should always be name-prefixed to avoid conflict, if you're going to use them at all:
-[UIImageView af_setImageWithURL:]
- nupark2 15y agoAs a follow-up -- are there any of the authors here? The implementation looks pretty good, but some questions. It looks like you might be using -[NSRunLoop run] to spin a background runloop? That will return immediately if no sources are scheduled in the runloop, which will result in a CPU-heavy busy-waiting thread -- unless I'm missing something here? I was also wondering about choices like the use of a single statically allocated serial dispatch queue for performing all JSON parsing, rather than using concurrent queues and letting GCD figure out how much concurrency to leverage given the application state and hardware available. Also, it appears that all callbacks are directly dispatched onto the main thread. Is there any interest in adding support for allowing the caller to specify dispatch onto other queues, in the case that they don't want to hit the main queue for background processing?
- matttthompson 15y agoHey, I'm the primary creator of AFNetworking. - As I understand threading and run loop scheduling, the run loop will spin up as needed when an NSURLConnection attaches itself to it, and back down again when no more connections are active. The dedicated network thread is there only to manage that run loop. - Regarding processing queues, like the JSON one, I thought it would be a good idea to isolate that from the global queue; it could always target another queue if needed. Also, unless I'm mistaken, those queues should be concurrent rather than serial. - As for dispatching to the main thread, this only happens it after all of the work in the operation is done. This just seems like good default behavior. If you wanted to, you could very easily override this by manually setting the `completionBlock` yourself.