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
usesNSURLConnection
internally.If you simply call
start
on the operation yourself it will execute the request on a background thread supplied byNSURLConnection
. 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 byAFJSONRequestOperation
, or viaKey Value Observing
theisFinished
property of theNSOperation
.Alternatively, because
AFJSONRequestOperation
is anNSOperation
you can add this to anNSOperationQueue
that you have created or perhaps one provided by some other framework feature. In that case theNSOperationQueue
will call thestart
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.