Is it possible and safe to set the SFNetworkOperation tag in the method initiating the request, and then read it back in the delegate method, to distinguish which request was made? Or is there a better way? I've considered creating a delegate for every call. I'd prefer not to use blocks. I've also seen solutions that (when using custom apex) wrap the return data in a json wrapper with an identifier as a distinguisher instead.
It appears to work with code like this (however I'm wondering if the delegate may get entered before the tag is set):
SFNetworkOperation *netop = [[SFRestAPI sharedInstance] send:request delegate:_delegate]; netop.tag = @"Test";
Attribution to: Brad Thomas
Possible Suggestion/Solution #1
Why not use blocks? Blocks make it super easy to enqueue multiple async requests, you'll always know which request has just completed, and they're becoming increasingly commonplace as a good design pattern. (Disclaimer: I contributed the blocks category to the API :)
If you're really set on not using blocks -- why again? -- then you could associate arbitrary data to your SFRestRequest
with the same runtime functions used by the blocks category.
Another option is to keep a reference to your SFRestRequest
(s) and, in the completion delegate, determine which request has just completed.
Attribution to: Jonathan Hersh
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30378