I'm writing a program for the iPhone that will need to call web services (asynchronously). I'd like to create a helper class that will abstract away some of the complexity of using the NSURLConnection class from my various view controllers.
The approach that I'm currently taking is to extend the NSURLConnection class so that it has 4 additional properties:
- (ID*)requestContext - An arbitrary object that contains contextual information about a given web service request.
- (ID*)requestingObject - A reference back to the object that is requesting the data (probably a ViewController)
- (SEL)onSuccessCallback - A selector that will be run on requestingObject when/if the web service call is made successfully. It will be assumed that this selector takes 2 parameters: (ID*)requestContext and (NSData*) responseData
- (SEL)onFailureCallback - Similar to onSuccessCallback, but passes an NSError instead of NSData
My web service helper class will be the delegate for the extended NSURLConnection class.
When "connectionDidFinishLoading" or "didFailWithError" is called, "onSuccessCallback" or "onFailureCallback" will be called on "requestingObject" assuming that they support the selector.
My question is simply "Is this a good approach?"
I'm very new to iPhone development and I'm trying to get my handle around all of it, so if there is an easier/more obvious way, please direct me to it!
Thanks