I currently have a view controller that implements ASIHTTP for handling API calls.
My view controller fires two separate calls. I need to be able to distinguish between the two calls in the -requestFinished(ASIHTTPRequest*) request method, so I can parse each one accordingly…
Is there any of doing this?
Use the userInfo field! That’s what it’s for!
An ASIHTTPRequest (or an ASIFormDataRequest) object has a property called .userInfo that can take an NSDictionary with anything in it you want. So I pretty much always go:
Set a different value for the object at key
@"type"in each different ASIHTTPRequest you do in this view controller, and you can now distinguish between them in-requestFinished:and handle each of them appropriately.If you’re really fancy, you can carry along any other data that would be useful when the request finishes. For instance, if you’re lazy-loading images, you can pass yourself a handle to the UIImageView that you want to populate, and then do that in
-requestFinishedafter you’ve loaded the image data!