Lets say I have something like this:
AFJSONRequestOperation *operation = ...
[operation start];
When operation start is called, where is that operation placed ? In which queue? Is there any global (for class) operation queue where this operation is placed and I can access this operation ?
Because I would need to call (in some cases) [operation stop] (maybe not called like that, but just to remove operation from queue, and to stop it) from another method, is there a way to do it ?
Or should I use instance variable AFJSONRequestOperation and then access it like that? Although I have many different operations and that would make me create many instance variables so if there is some other way.
Thank you.
I'm not particularly familiar with AFNetworking, but as far as I know AFJSONRequestOperation
uses NSURLConnection
internally.
If you simply call start
on the operation yourself it will execute the request on a background thread supplied by NSURLConnection
. It will not therefore be in any queue. You should keep a reference to the operation yourself to stop it being deallocated, and use some kind of callback or block to handle the results, perhaps something provided by AFJSONRequestOperation
, or via Key Value Observing
the isFinished
property of the NSOperation
.
Alternatively, because AFJSONRequestOperation
is an NSOperation
you can add this to an NSOperationQueue
that you have created or perhaps one provided by some other framework feature. In that case the NSOperationQueue
will call the start
method for you, and manage the objects lifetime as it is being processed. Again you will have to determine the best way to handle the results when the operation finishes.